• QTday3


    思维导图

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

    要求: 1. qss实现

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

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

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

    mian.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. }

    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. ui->setupUi(this);
    9. //去掉头部
    10. this->setWindowFlag(Qt::FramelessWindowHint);
    11. //去掉空白部分
    12. this->setAttribute(Qt::WA_TranslucentBackground);
    13. }
    14. Widget::~Widget()
    15. {
    16. delete ui;
    17. }
    18. void Widget::on_pushButton_clicked()
    19. {
    20. QString zhanghao = ui->lineEdit->text();//定义账号输入的字符串为zhanghao
    21. QString mima = ui->lineEdit_2->text();//
    22. if(zhanghao == "admin" && mima == "123456")//判断账号密码的正确性
    23. {
    24. this->close();//若都正确,则退出窗口
    25. //触发信号
    26. emit my_jump();
    27. }
    28. else
    29. {
    30. ui->lineEdit_2->clear();//清除密码框内容
    31. }
    32. }
    33. void Widget::on_cha_clicked()
    34. {
    35. this->close();
    36. }
    37. void Widget::on_max_clicked()
    38. {
    39. this->showMaximized();
    40. }
    41. void Widget::on_min_clicked()
    42. {
    43. this->showMinimized();
    44. }

    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. this->show();
    16. }

    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_jump();//第一个界面的信号
    16. private slots:
    17. void on_pushButton_clicked();
    18. void on_cha_clicked();
    19. void on_max_clicked();
    20. void on_min_clicked();
    21. private:
    22. Ui::Widget *ui;
    23. };
    24. #endif // WIDGET_H

    ssecond.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

  • 相关阅读:
    【安装OpenFPGA】经验分享
    金翅擘海 | 人大加拿大女王大学金融硕士王立印:一路向阳 沿途芬芳
    【HTML】标签学习(下.3)
    Vue3待办列表-日记与便签-LOL英雄资料-课程大作业
    第十章·桥接模式
    DAY04 HTML&CSS
    Mybatis-Plus——ListTypeHandler处理类型为list<T>字段的增改查
    为什么数字IC的模块输出要尽量写成寄存器(reg)类型?
    AFL模糊测试
    AIGC笔记--基于DDPM实现图片生成
  • 原文地址:https://blog.csdn.net/Pharaoh420_/article/details/139755405