//widget.cpp#include "widget.h"
#include "ui_widget.h"void Widget::usr_login()
{if("admin" == this->edit_acc->text()){if("123456" == this->edit_psd->text()){speech->say("登录成功");emit jump_sig1();this->hide();}else {speech->say("账号或密码错误");this->edit_psd->clear();}return;}speech->say("账号或密码错误");this->edit_psd->clear();
}Widget::Widget(QWidget *parent) :QWidget(parent),ui(new Ui::Widget)
{ui->setupUi(this);//设置窗口标题this->setWindowTitle("第七史诗");//设置窗口iconthis->setWindowIcon(QIcon(":/icon/1.png"));//设置窗口大小this->resize(QSize(500,400));//创建标签,设置图片this->lab_front = new QLabel(this);lab_front->setPixmap(QPixmap(":/icon/logo.png"));lab_front->setScaledContents(true);lab_front->resize(500,200);lab_acc = new QLabel(this);lab_acc->setPixmap(QPixmap(":/icon/userName.jpg"));lab_acc->setScaledContents(true);lab_acc->resize(40,30);lab_acc->move(100,lab_front->y() + lab_front->height() + 30);lab_psd = new QLabel(this);lab_psd->setPixmap(QPixmap(":/icon/passwd.jpg"));lab_psd->resize(lab_acc->size());lab_psd->setScaledContents(true);lab_psd->move(lab_acc->x(),lab_acc->y() + 50);//增加单行编辑器edit_acc = new QLineEdit(this);edit_acc->setPlaceholderText("stove账号/邮箱");cout << lab_acc->width() << endl;edit_acc->move(lab_acc->x() + lab_acc->width() + 50,lab_acc->y());edit_psd = new QLineEdit(this);edit_psd->setPlaceholderText("密码");edit_psd->move(edit_acc->x(),edit_acc->y() + 50);//设置输入内容隐藏edit_psd->setEchoMode(QLineEdit :: Password);//登录按钮btn_login = new QPushButton("登录",this);btn_login->setIcon(QIcon(":/icon/login.png"));btn_login->move(300,edit_psd->y() + edit_psd->height() + 30);//取消按钮btn_cancel = new QPushButton("取消",this);btn_cancel->setIcon(QIcon(":/icon/cancel.png"));btn_cancel->move(btn_login->x() + btn_login->width() + 10,btn_login->y());//设置语音播报speech = new QTextToSpeech(this);server = new QComboBox(this);server->addItem("日本服务器");server->addItem("韩国服务器");server->addItem("国际服务器");server->move(50,btn_cancel->y());connect(btn_cancel,&QPushButton :: clicked,this,&Widget :: close);connect(btn_login,&QPushButton :: clicked,this,&Widget :: usr_login);}Widget::~Widget()
{delete ui;
}
//widget.h#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include <QSize>
#include <QPushButton>
#include <QLineEdit>
#include <QLabel>
#include <QComboBox>
#include <iostream>
#include <QString>
#include <QDebug>
#include <QTextToSpeech>
#include <windows.h>using namespace std;namespace Ui {
class Widget;
}class Widget : public QWidget
{Q_OBJECTpublic:
signals:void my_signal();void jump_sig1();
public slots:void usr_login();public:explicit Widget(QWidget *parent = nullptr);~Widget();private:Ui::Widget *ui;QLabel *lab_front,*lab_acc,*lab_psd;QLineEdit *edit_acc,*edit_psd;QPushButton *btn_login,*btn_cancel;QComboBox *server;QTextToSpeech *speech;};//void Widget :: jump_sig1()
//{
// this->hide();
//}#endif // WIDGET_H
//form.h#ifndef FORM_H
#define FORM_H#include <QWidget>
#include "widget.h"
namespace Ui {
class Form;
}class Form : public QWidget
{Q_OBJECTpublic slots:void jump_slot();public:explicit Form(QWidget *parent = nullptr);~Form();private:Ui::Form *ui;QPushButton *return_key;
};#endif // FORM_H
//form.cpp#include "form.h"
#include "ui_form.h"void Form::jump_slot()
{this->show();
}Form::Form(QWidget *parent) :QWidget(parent),ui(new Ui::Form)
{ui->setupUi(this);this->resize(QSize(800,700));return_key = new QPushButton(this);return_key->resize(80,70);QPixmap icon1(":/icon/return.png");icon1.scaled(return_key->size());// QLabel *lab = new QLabel(this);
// lab->setPixmap(icon1);return_key->setIcon(icon1);return_key->setStyleSheet("background-image:url(:/icon/return.png)");return_key->move(300,200);}Form::~Form()
{delete ui;
}
//main.cpp#include "widget.h"
#include <QApplication>
#include "form.h"int main(int argc, char *argv[])
{QApplication a(argc, argv);Widget w;w.show();Form f;//f.show();QObject :: connect(&w,&Widget :: jump_sig1,&f,&Form :: jump_slot);return a.exec();
}
运行效果
登录成功后跳转from界面