升级优化自己应用程序的登录界面。
要求: 1. qss实现
2. 需要有图层的叠加 (QFrame)
3. 设置纯净窗口后,有关闭等窗口功能。
4. 如果账号密码正确,则实现登录界面关闭,另一个应用界面显示。
//发送端头文件#ifndef MYWIDGET_H #define MYWIDGET_H#include <QWidget>QT_BEGIN_NAMESPACE namespace Ui { class MyWidget; } QT_END_NAMESPACEclass MyWidget : public QWidget {Q_OBJECTpublic:MyWidget(QWidget *parent = nullptr);~MyWidget();private slots:void on_pushButton_clicked();void on_pushButton_2_clicked();void on_pushButton_3_clicked();void on_pushButton_4_clicked();signals:void my_signal_1();void my_signal_2();void my_jump();private:Ui::MyWidget *ui;QPalette color; }; #endif // MYWIDGET_H//发送端源文件#include "mywidget.h" #include "ui_mywidget.h"MyWidget::MyWidget(QWidget *parent): QWidget(parent), ui(new Ui::MyWidget) {ui->setupUi(this);this->setWindowFlag(Qt::FramelessWindowHint);this->setAttribute(Qt::WA_TranslucentBackground);connect(this,&MyWidget::my_signal_1,[=](){this->showMinimized();});connect(this,&MyWidget::my_signal_2,[=](){if(this->window()->isMaximized()){this->showNormal();}else{this->showMaximized();}}); }MyWidget::~MyWidget() {delete ui; }void MyWidget::on_pushButton_clicked() {if(ui->Username->text() == "admin" && ui->Passwd->text() == "123456"){this->close();emit my_jump();}else{ui->Username->setText("账号或密码不正确!");ui->Passwd->clear();} }void MyWidget::on_pushButton_2_clicked() {this->close(); }void MyWidget::on_pushButton_3_clicked() {emit my_signal_1(); }void MyWidget::on_pushButton_4_clicked() {emit my_signal_2(); }//接收端头文件#ifndef SECOND_H #define SECOND_H#include <QWidget> #include <QMovie>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//接收端源文件#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() {QMovie *mv = new QMovie(":/e043-iquxrui6424394.gif");ui->label->setMovie(mv);mv->start();ui->label->setScaledContents(1);this->show(); }//主函数#include "mywidget.h" #include "second.h"#include <QApplication>int main(int argc, char *argv[]) {QApplication a(argc, argv);MyWidget w;w.show();Second s;QObject::connect(&w,&MyWidget::my_jump,&s,&Second::jump_slot);return a.exec(); }