2、升级优化自己应用程序的登录界面。
要求: 1. qss实现
2. 需要有图层的叠加 (QFrame)
3. 设置纯净窗口后,有关闭等窗口功能。
4. 如果账号密码正确,则实现登录界面关闭,另一个应用界面显示。
头文件mywidget.h
#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();signals:void my_jump(); //private slots:void on_pushButton_2_clicked();void on_pushButton_clicked();private:Ui::MyWidget *ui;
};
#endif // MYWIDGET_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
main.cpp
#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();
}
mywidget.cpp
#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);
}MyWidget::~MyWidget()
{delete ui;
}void MyWidget::on_pushButton_2_clicked()
{this->close();
}void MyWidget::on_pushButton_clicked()
{if(ui->lineEdit->text()=="admin" && ui->lineEdit_2->text()=="123456"){//this->close();//emit my_jump();}else{//QMessageBox::information(this,"Error","密码或账号错误");ui->lineEdit->clear();ui->lineEdit_2->clear();}
}
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();
}
思源笔记