升级优化自己应用程序的登录界面。
要求: 1. qss实现
2. 需要有图层的叠加 (QFrame)
3. 设置纯净窗口后,有关闭等窗口功能。
4. 如果账号密码正确,则实现登录界面关闭,另一个应用界面显示。
mian.cpp
- #include "widget.h"
- #include "second.h"
- #include
-
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- Widget w;
- w.show();
- Second s;
- QObject::connect(&w,&Widget::my_jump,&s,&Second::jump_slot);
- return a.exec();
- }
widget.cpp
- #include "widget.h"
- #include "ui_widget.h"
-
- Widget::Widget(QWidget *parent)
- : QWidget(parent)
- , ui(new Ui::Widget)
- {
- ui->setupUi(this);
- ui->setupUi(this);
- //去掉头部
- this->setWindowFlag(Qt::FramelessWindowHint);
- //去掉空白部分
- this->setAttribute(Qt::WA_TranslucentBackground);
- }
-
- Widget::~Widget()
- {
- delete ui;
- }
-
- void Widget::on_pushButton_clicked()
- {
- QString zhanghao = ui->lineEdit->text();//定义账号输入的字符串为zhanghao
- QString mima = ui->lineEdit_2->text();//
- if(zhanghao == "admin" && mima == "123456")//判断账号密码的正确性
- {
- this->close();//若都正确,则退出窗口
- //触发信号
- emit my_jump();
- }
- else
- {
- ui->lineEdit_2->clear();//清除密码框内容
- }
- }
-
- void Widget::on_cha_clicked()
- {
- this->close();
- }
-
- void Widget::on_max_clicked()
- {
- this->showMaximized();
- }
-
- void Widget::on_min_clicked()
- {
- this->showMinimized();
- }
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();
- }
widget.h
- #ifndef WIDGET_H
- #define WIDGET_H
-
- #include
- #include
- QT_BEGIN_NAMESPACE
- namespace Ui { class Widget; }
- QT_END_NAMESPACE
-
- class Widget : public QWidget
- {
- Q_OBJECT
-
- public:
- Widget(QWidget *parent = nullptr);
- ~Widget();
- signals:
- void my_jump();//第一个界面的信号
-
- private slots:
- void on_pushButton_clicked();
-
- void on_cha_clicked();
-
- void on_max_clicked();
-
- void on_min_clicked();
-
- private:
- Ui::Widget *ui;
- };
- #endif // WIDGET_H
ssecond.h
- #ifndef SECOND_H
- #define SECOND_H
-
- #include
-
- namespace Ui {
- class Second;
- }
-
- class Second : public QWidget
- {
- Q_OBJECT
-
- public:
- explicit Second(QWidget *parent = nullptr);
- ~Second();
- public slots:
- void jump_slot();
- private:
- Ui::Second *ui;
- };
-
- #endif // SECOND_H
