#include
#include
QT_BEGIN_NAMESPACE
namespace Ui { class hqyj; }
QT_END_NAMESPACE
class hqyj : public QWidget
{
Q_OBJECT
public:
hqyj(QWidget *parent = nullptr);
~hqyj();
signals:
void jumpToLogin();
public slots:
void loginBtn_slot();
void cancelBtn_slot();
private:
Ui::hqyj *ui;
QLabel*lab1 = new QLabel(this);
QLineEdit *edit1 = new QLineEdit(this);
QLineEdit *edit2 = new QLineEdit(this);
QLabel *lab2 = new QLabel(this);
QLabel *lab3 = new QLabel(this);
QPushButton *btn1 = new QPushButton("登录",this);
QPushButton *btn2 = new QPushButton("取消",this);
login *l1 = new login;;
};
#endif // HQYJ_H
#ifndef LOGIN_H
#define LOGIN_H
#include
namespace Ui {
class login;
}
class login : public QDialog
{
Q_OBJECT
public slots:
void jumpToLogin_slot();
public:
explicit login(QWidget *parent = nullptr);
~login();
private:
Ui::login *ui;
};
#endif // LOGIN_H
#include "hqyj.h"
#include
#include
#include "ui_hqyj.h"
hqyj::hqyj(QWidget *parent)
: QWidget(parent)
, ui(new Ui::hqyj)
{
ui->setupUi(this);
this->setWindowTitle("Widget");
this->setWindowIcon(QIcon("D:\\230906C++&Qt\\icon\\wodepeizhenshi.png"));
this->setFixedSize(QSize(400,300));
lab1->resize(QSize(400,133));
lab1->move(0,0);
lab1->setPixmap(QPixmap("D:\\230906C++&Qt\\icon\\logo.png"));
lab1->setScaledContents(true);
edit1->resize(QSize(240,40));
edit1->move(110,150);
edit1->setPlaceholderText("账号");
edit2->resize(QSize(240,40));
edit2->move(edit1->x(),edit1->y()+55);
edit2->setPlaceholderText("密码");
edit2->setEchoMode(QLineEdit::Password);
lab2->resize(50,40);
lab2->setPixmap(QPixmap("D:\\230906C++&Qt\\icon\\userName.jpg"));
lab2->setScaledContents(true);
lab2->move(edit1->x()-60,edit1->y());
lab3->resize(50,40);
lab3->setPixmap(QPixmap("D:\\230906C++&Qt\\icon\\passwd.jpg"));
lab3->setScaledContents(true);
lab3->move(edit2->x()-60,edit2->y());
btn1->resize(QSize(60,30));
btn2->resize(btn1->size());
btn1->move(120,edit2->y()+55);
btn2->move(btn1->x()+120,edit2->y()+55);
btn1->setIcon(QIcon("D:\\230906C++&Qt\\icon\\login.png"));
btn2->setIcon(QIcon("D:\\230906C++&Qt\\icon\\cancel.png"));
connect(btn1,&QPushButton::clicked,this,&hqyj::loginBtn_slot);
connect(btn2,&QPushButton::clicked,this,&hqyj::cancelBtn_slot);
connect(this,&hqyj::jumpToLogin,l1,&login::jumpToLogin_slot);
}
hqyj::~hqyj()
{
delete ui;
}
void hqyj::loginBtn_slot()
{
if(edit1->text()==QString("damin")&&edit2->text()==QString("123456"))
{
QMessageBox box(QMessageBox::Information,
"登录成功",
"登录成功",
QMessageBox::Ok,
this);
box.exec();
emit this->jumpToLogin();
this->close();
}else
{
QMessageBox box(QMessageBox::Critical,
"错误",
"账号密码不匹配,是否重新登录",
QMessageBox::Ok|QMessageBox::Cancel,
this);
box.setDefaultButton(QMessageBox::Ok);
int ret = box.exec();
if(QMessageBox::Ok==ret)
{
edit2->clear();
}else
this->close();
}
}
void hqyj::cancelBtn_slot()
{
int ret = QMessageBox::question(this,
"请问",
"是否确认要退出",
QMessageBox::Yes|QMessageBox::No,
QMessageBox::No);
switch(ret)
{
case QMessageBox::Yes:
this->close();
break;
case QMessageBox::No:
break;
default:
break;
}
}
#include "login.h"
#include "ui_login.h"
login::login(QWidget *parent) :
QDialog(parent),
ui(new Ui::login)
{
ui->setupUi(this);
}
login::~login()
{
delete ui;
}
void login::jumpToLogin_slot()
{
this->show();
}

