今日作业:
升级优化自己应用程序的登录界面。
要求: 1. qss实现
2. 需要有图层的叠加 (QFrame)
3. 设置纯净窗口后,有关闭等窗口功能。
4. 如果账号密码正确,则实现登录界面关闭,另一个应用界面显示。
//day3_04.h
#ifndef DAY3_04_H
#define DAY3_04_H#include <QWidget>
#include <QMessageBox>QT_BEGIN_NAMESPACE
namespace Ui { class day3_04; }
QT_END_NAMESPACEclass day3_04 : public QWidget
{Q_OBJECTpublic:day3_04(QWidget *parent = nullptr);~day3_04();signals:void my_jump(); //第一个界面的信号private slots:void on_pushButton_2_clicked();void on_pushButton_clicked();void on_pushButton_6_clicked();private:Ui::day3_04 *ui;
};
#endif // DAY3_04_H
//Second.h
#ifndef SECOND_H
#define SECOND_H#include <QWidget>namespace Ui {
class Second;
}class Second : public QWidget
{Q_OBJECTpublic:explicit Second(QWidget *parent = nullptr);~Second();public slots:void jump_slot(); //第二个界面准备的槽函数private:Ui::Second *ui;
};#endif // SECOND_H
//day3_04.cpp
#include "day3_04.h"
#include "ui_day3_04.h"day3_04::day3_04(QWidget *parent): QWidget(parent), ui(new Ui::day3_04)
{ui->setupUi(this);//去掉头部this->setWindowFlag(Qt::FramelessWindowHint);//去掉空白部分this->setAttribute(Qt::WA_TranslucentBackground);
}day3_04::~day3_04()
{delete ui;
}void day3_04::on_pushButton_2_clicked()
{this->close();
}void day3_04::on_pushButton_clicked()
{//获取输入的文本QString user1 = ui->user->text();QString line1 = ui->line->text();if(user1.isEmpty() || line1.isEmpty()){QMessageBox::warning(this, "Warning", "请输入账号或密码");}else{//判断账号和密码正确性if(user1 == "admin" && line1 == "123456"){//关闭窗口this->close();//触发信号emit my_jump();}else{QMessageBox::warning(this, "Access Denied", "登录失败:密码错误");ui->user->clear();ui->line->clear();}}
}void day3_04::on_pushButton_6_clicked()
{this->showMinimized();
}
//main.cpp
#include "day3_04.h"
#include "second.h" //包含第二个头文件#include <QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);//实例化第一个界面day3_04 w;w.show();//实例化第二个界面Second s;//连接QObject::connect(&w, &day3_04::my_jump, &s, &Second::jump_slot);return a.exec();
}
//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();
}