0209作业
思维导图
作业
优化登录框:
当用户点击取消按钮,弹出问题对话框
询问是否要确定退出登录,并提供两个按钮,yeSINO,
如果用户点击的Yes,则关闭对话
框,如果用户点击的NO,则继续登录
当用户点击的登录按钮,进行账号和密码的匹配,如果匹配成功,则弹出信息对话框,给出信息为,登录成功,并给出一个确定按
钮,当用户点击该按钮后,关闭登录界面,弹出另一个界面
当账号和密码不匹配是,给出错误对话框,给出信息为账号和密码不匹配,是否重新登录,并提供两个按钮
Yes|N0,如果用户点击了Yes,则清空密码框后,继续登录。如果用户点击的取消,则关闭登录界面
要求:静态成员函数版本和对象版本各至少实现一个
widget.cpp
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
//设置界面尺寸
//this->resize(320,448);
this->setFixedSize(320,448);
this->setWindowFlag(Qt::FramelessWindowHint);
this->setStyleSheet("background-color:white");
this->setWindowOpacity(0.7);
//按钮组件
btn1 = new QPushButton("登陆",this);
btn1->setStyleSheet("background-color:blue;color:white");
btn1->setWindowOpacity(0.5);
btn1->resize(110,40);
btn1->move(30,320);
btn2 = new QPushButton("取消",this);
btn2->setStyleSheet("background-color:blue;color:white");
btn2->setWindowOpacity(0.5);
btn2->resize(btn1->size());
btn2->move(btn1->x()+btn1->width()+40,btn1->y());
btn3 = new QRadioButton("已阅读并同意服务协议和QQ隐私保护指引",this);
btn3->setStyleSheet("background-color:white;color:black");
btn3->setWindowOpacity(0.7);
btn3->move(30,290);
//行编辑器
edit1 = new QLineEdit(this);
edit1->resize(260,50);
edit1->setStyleSheet("background-color:white");
edit1->setWindowOpacity(0.3);
edit1->move(30,170);
edit1->setAlignment(Qt::AlignCenter);
edit1->setPlaceholderText("输入QQ账号");
edit2 = new QLineEdit(this);
edit2->resize(edit1->size());
edit2->setStyleSheet("background-color:white");
edit2->setWindowOpacity(0.3);
edit2->move(edit1->x(),edit1->y()+edit1->height()+10);
edit2->setAlignment(Qt::AlignCenter);
edit2->setPlaceholderText("输入QQ密码");
edit2->setEchoMode(QLineEdit::Password);
//标签类
lab = new QLabel(this);
lab->resize(80,80);
lab->setStyleSheet("background-color:white");
lab->setWindowOpacity(0.7);
lab->setPixmap(QPixmap(":/tupian/QQ_1739084470578.png"));
lab->move(120,60);
QObject::connect(btn1,
&QPushButton::clicked,
this,
&Widget::clicked_slot);
QObject::connect(btn2,
&QPushButton::clicked,
this,
&Widget::clicked1_slot);
}
Widget::~Widget()
{
delete ui;
}
//按钮1的槽函数
void Widget::clicked_slot()
{
QString username = edit1->text();
QString password = edit2->text();
if(username==password)
{
QMessageBox box(QMessageBox::Information,
"提示",
"登陆成功",
QMessageBox::Yes,
this);
box.setWindowFlag(Qt::FramelessWindowHint);
box.setButtonText(QMessageBox::Yes,"确定");
int res = box.exec();
if(res==QMessageBox::Yes)
{
this->close();
emit jump();
}
}
else
{
QMessageBox box1(QMessageBox::Critical,
"错误",
"账号和密码不匹配",
QMessageBox::Yes | QMessageBox::No,
this);
box1.setWindowFlag(Qt::FramelessWindowHint);
int res = box1.exec();
if(res==QMessageBox::Yes)
{
edit2->clear();
}
else
{
this->close();
}
}
}
//按钮2的槽函数
void Widget::clicked1_slot()
{
int res = QMessageBox::question(
this,
"问题",
"是否确定退出登录",
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes
);
if(res==QMessageBox::Yes)
{
this->close();
}
}
second.cpp
#include "second.h"
#include "ui_second.h"
second::second(QWidget *parent) :
QWidget(parent),
ui(new Ui::second)
{
ui->setupUi(this);
}
second::~second()
{
delete ui;
}
//跳转槽函数
void second::jump_slot()
{
this->show();
}
main.cpp
#include "widget.h"
#include"second.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
second s;
QObject::connect(&w,&Widget::jump,&s,&second::jump_slot);
return a.exec();
}
效果展示