思维导图
将day1做的登录界面升级优化【资源文件的添加】
在登录界面的登录取消按钮进行一下设置:
使用手动连接,将登录框中的取消按钮使用qt4版本的连接到自定义的槽函数中,在自定义的槽函数中调用关闭函数
将登录按钮使用qt5版本的连接到自定义的槽函数中,在槽函数中判断ui界面上输入的账号是否为"admin",密码是否为"123456",如果账号密码匹配成功,则输出“登录成功”,并关闭该界面,如果匹配失败,则输出登录失败,并将密码框中的内容清空
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
, lab2(new QLabel(this))
, line1(new QLineEdit(this))
, line2(new QLineEdit(this))
{
ui->setupUi(this);
//窗口设置
//设置窗口标题
this->setWindowTitle("TCP智汇云辞通");
//设置窗口图标
this->setWindowIcon(QIcon(":/pictrue/tubiao.png"));
//重设窗口大小
this->resize(540,415);
//设置纯净窗口
//this->setWindowFlag(Qt::FramelessWindowHint);
//标签设置
//创建第一个标签
QLabel *lab1 = new QLabel(this);
//设置标签大小
lab1->resize(540,160);
//实例化一个动图指针
QMovie *mov = new QMovie(":/pictrue/fy.gif");
//动图设置到标签中
lab1->setMovie(mov);
//图动起来
mov->start();
//图片自动适应lab
lab1->setScaledContents(true);
//设置标签大小
lab2->resize(540,255);
//移动
lab2->move(0,160);
//设置图片
lab2->setPixmap(QPixmap(":/pictrue/guan.jpeg"));
//图片自动适应lab
lab2->setScaledContents(true);
//创建第三个标签
QLabel *lab3 = new QLabel(this);
//设置标签大小
lab3->resize(30,30);
//移动
lab3->move(115,200);
//设置图片
lab3->setPixmap(QPixmap(":/pictrue/dl.jpeg"));
//图片自动适应lab
lab3->setScaledContents(true);
//创建第四个标签
QLabel *lab4 = new QLabel(this);
//设置标签大小
lab4->resize(30,30);
//移动
lab4->move(115,250);
//设置图片
lab4->setPixmap(QPixmap(":/pictrue/s.jpeg"));
//图片自动适应lab
lab4->setScaledContents(true);
//行编辑器设置
//设置行编辑器大小
line1->resize(280,30);
//移动
line1->move(150,200);
//设置占位
line1->setPlaceholderText("账号");
//设置行编辑器大小
line2->resize(280,30);
//移动
line2->move(150,250);
//设置占位
line2->setPlaceholderText("密码");
//设置显示模式
line2->setEchoMode(QLineEdit::Password);
//按钮设置
QPushButton *push1 = new QPushButton("登录",this);
//设置按钮大小
push1->resize(120,40);
//移动
push1->move(130,310);
//设置按钮背景颜色、按钮文本颜色、倒角
push1->setStyleSheet("background-color:rgb(50,130,246);color:white;border-radius:5px");
QPushButton *push2 = new QPushButton("退出",this);
//设置按钮大小
push2->resize(120,40);
//移动
push2->move(270,310);
//设置按钮背景颜色、按钮文本颜色、倒角
push2->setStyleSheet("background-color:rgb(50,130,246);color:white;border-radius:5px");
connect(push2,SIGNAL(clicked()),this,SLOT(slot_1()));
connect(push1,&QPushButton::clicked,this,&Widget::slot_2);
}
Widget::~Widget()
{
delete ui;
}
void Widget::slot_1()
{
this->close();
}
void Widget::slot_2()
{
if(line1->text() == "admin" && line2->text() == "123456")
{
qDebug() << "登陆成功";
this->close();
}
else
{
qDebug() << "登陆失败";
line2->clear();
}
}