• Qt creator day3练习


    2、升级优化自己应用程序的登录界面。

    要求: 1. qss实现

    2. 需要有图层的叠加 (QFrame)

    3. 设置纯净窗口后,有关闭等窗口功能。

    4. 如果账号密码正确,则实现登录界面关闭,另一个应用界面显示。

    widget.h

    1. #ifndef WIDGET_H
    2. #define WIDGET_H
    3. #include
    4. #include
    5. QT_BEGIN_NAMESPACE
    6. namespace Ui { class Widget; }
    7. QT_END_NAMESPACE
    8. class Widget : public QWidget
    9. {
    10. Q_OBJECT
    11. public:
    12. Widget(QWidget *parent = nullptr);
    13. ~Widget();
    14. signals:
    15. void my_signal(); //信号函数的声明
    16. void my_jump(); //第一个界面的跳转信号
    17. private slots:
    18. void on_pushButton_2_clicked();
    19. void on_pushButton_3_clicked();
    20. void on_pushButton_clicked();
    21. private:
    22. Ui::Widget *ui;
    23. };
    24. #endif // WIDGET_H

    second.h

    1. #ifndef SECOND_H
    2. #define SECOND_H
    3. #include
    4. namespace Ui {
    5. class Second;
    6. }
    7. class Second : public QWidget
    8. {
    9. Q_OBJECT
    10. public:
    11. explicit Second(QWidget *parent = nullptr);
    12. ~Second();
    13. public slots:
    14. void jump_slot(); //第二个界面准备的槽函数
    15. private:
    16. Ui::Second *ui;
    17. };
    18. #endif // SECOND_H

    widget.cpp

    1. #include "widget.h"
    2. #include "ui_widget.h"
    3. Widget::Widget(QWidget *parent)
    4. : QWidget(parent)
    5. , ui(new Ui::Widget)
    6. {
    7. ui->setupUi(this);
    8. //将自定义的信号和Lambda表达式连接
    9. connect(this,&Widget::my_signal,[=](){
    10. //ui->resize(ui->width()+10,ui->height()+10);
    11. });
    12. //去掉头部
    13. this->setWindowFlag(Qt::FramelessWindowHint);
    14. //去掉空白部分
    15. this->setAttribute(Qt::WA_TranslucentBackground);
    16. connect(ui->lineEdit_2,SIGNAL(returnPressed()),ui->pushButton //回车键登录
    17. ,SIGNAL(clicked()),Qt::UniqueConnection);
    18. }
    19. Widget::~Widget()
    20. {
    21. delete ui;
    22. }
    23. void Widget::on_pushButton_2_clicked()
    24. {
    25. this->close();
    26. }
    27. void Widget::on_pushButton_3_clicked()
    28. {
    29. }
    30. void Widget::on_pushButton_clicked()
    31. {
    32. QMessageBox *box = new QMessageBox(); //实例化一个box,用来弹出消息
    33. box->setWindowTitle("提示");
    34. if(QString(ui->lineEdit->text()) == "admin" && QString(ui->lineEdit_2->text()) == "123456")
    35. {
    36. box->setText("登录成功^_^");
    37. box->show();
    38. box->exec();
    39. this->close();
    40. emit my_jump(); // 触发信号
    41. }
    42. else
    43. {
    44. box->setText("账号密码错误");
    45. box->show(); //提示
    46. box->exec(); //等待用户响应
    47. ui->lineEdit->setText("");
    48. ui->lineEdit_2->setText("");
    49. }
    50. }

    second.cpp

    1. #include "second.h"
    2. #include "ui_second.h"
    3. Second::Second(QWidget *parent) :
    4. QWidget(parent),
    5. ui(new Ui::Second)
    6. {
    7. ui->setupUi(this);
    8. }
    9. Second::~Second()
    10. {
    11. delete ui;
    12. }
    13. void Second::jump_slot()
    14. {
    15. //显示
    16. this->show();
    17. }

    main.cpp

    1. #include "widget.h"
    2. #include "second.h" //包含第二个头文件
    3. #include
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. Widget w;
    8. w.show();
    9. Second s; //实例化第二个界面
    10. QObject::connect(&w, &Widget::my_jump, &s, &Second::jump_slot);
    11. return a.exec();
    12. }

  • 相关阅读:
    【AI】PyTorch入门(六):自动微分torch.autograd
    深圳铨顺宏圆满落幕IOTE 2022第十八届国际物联网展
    普冉PY32系列(六) 通过I2C接口驱动PCF8574扩展的1602LCD
    Docker数据卷
    博弈论专题
    Qt5开发从入门到精通——第九篇三节( Qt5 文件及磁盘处理—— 文件大小及路径获取实例)
    设置代理服务器
    【PHP框架 | Laravel8 系列2】 - 配置文件简介
    C 变量和类型
    解决编译中遇到的问题:Please port gnulib freadahead.c to your platform
  • 原文地址:https://blog.csdn.net/M_ningee21/article/details/139756046