完善登录界面
点击登录按钮后,判断账号(admin)和密码(123456)是否一致,如果匹配失败,则弹出错误对话框,文本内容“账号密码不匹配,是否重新登录”,给定两个按钮ok和cancel,点击ok后,会清除密码框中的内容,继续进行登录;如果点击cancel按钮,则关闭界面。
如果账号和密码匹配,则弹出信息对话框,给出提示信息为“登录成功”,给出一个按钮ok,点击ok后,关闭整个登录界面,跳转到其他界面
点击取消按钮后,弹出问题对话框,询问是否确定要退出登录,给出两个按钮,yes|no,点击yes,则直接关闭整个登录界面,如果点击no则进行进行登录
要求:对象版和静态成员函数版至少各实现一个
#include "mywindow.h"
MyWindow::MyWindow(QWidget *parent)
: QMainWindow(parent)
{
//设置窗口最大尺寸
this->setMaximumSize(1000,800);
//设置窗口最小尺寸
this->setMinimumSize(1000,800);
//设置窗口固定尺寸
this->setFixedSize(500,350);
//输出窗口名称
qDebug()<<this->windowTitle();
//设置窗口名称
this->setWindowTitle("QQ");
//更改图标
this->setWindowIcon(QIcon(":/icon/QQ.png"));
//更改窗口透明度
this->setWindowOpacity(0.9);
//设置纯净窗口
//this->setWindowFlag(Qt::FramelessWindowHint);
btn1->move(180,270);
btn1->resize(70,20);
btn2->move(270,270);
btn2->resize(70,20);
lbtn->resize(20,20);
lbtn->move(20,0);
line1->setEchoMode(QLineEdit::Password);
line1->move(170,240);
line1->resize(200,20);
line2->move(170,210);
line2->resize(200,20);
line1->setPlaceholderText("密码");
line2->setPlaceholderText("账号");
lbtn1->setScaledContents(true);
lbtn1->setPixmap(QPixmap(":/icon/denglumima.png"));
lbtn1->resize(20,20);
lbtn1->move(150,240);
lbtn2->setScaledContents(true);
lbtn2->setPixmap(QPixmap(":/icon/QQ.png"));
lbtn2->resize(20,20);
lbtn2->move(150,210);
lbtn3->setScaledContents(true);
lbtn3->setPixmap(QPixmap(":/icon/QQ.png"));
lbtn3->resize(20,20);
lbtn3->move(0,0);
lbtn4->setScaledContents(true);
lbtn4->setPixmap(QPixmap(":/icon/38adca8ffbfa47cf91e2d5254bbe1049.jpeg"));
lbtn4->resize(500,150);
lbtn4->move(0,50);
connect(btn1, &QPushButton::clicked, this, &MyWindow::on_btn1_clicked);
connect(btn2, &QPushButton::clicked, this, &MyWindow::on_btn2_clicked);
}
MyWindow::~MyWindow()
{
}
void MyWindow::on_btn1_clicked()
{
QString userName = MyWindow::line2->text(); //获取用户名称
QString password = MyWindow::line1->text();;//获取密码
if(userName == "admin" && password == "123456")
{
QMessageBox::information(this,"information","登陆成功",QMessageBox::Ok);
this->close();
}
else
{
QMessageBox box2(QMessageBox::Critical,"error","登陆失败",QMessageBox::Yes | QMessageBox::No);
int res = box2.exec();
if(res == QMessageBox::Yes)
{
MyWindow::line1->clear();
MyWindow::line2->clear();
}else if(res == QMessageBox::No)
{
this->close();
}
}
}
void MyWindow::on_btn2_clicked()
{
QMessageBox::StandardButtons ret=QMessageBox::warning(this,
"警告",
"确认要退出吗",
QMessageBox::Ok|QMessageBox::No,
QMessageBox::Ok);
if(ret==QMessageBox::Ok)
{
this->close();
}
}