• QT_day3


    1.思维导图

    2.完善对话框,点击登录对话框,如果账号和密码匹配,则弹出信息对话框,给出提示"登录成功“,提供一个Ok按钮,用户点击Ok后,关闭登录界面,跳转到其他界面
    如果账号和密码不匹配,弹出错误对话框,给出信息”账号和密码不匹配,是否重新登录“,并提供两个按钮
    YeslNo,用户点击Yes后,清除密码框中的内容,继续让用户进行登录,如果用户点击No按钮,则直接关闭登录界面
    如果用户点击取消按钮,则弹出一个问题对话框,给出信息”您是否确定要退出登录?“,并给出两个按钮Yes/No,用户迪纳基Yes后,关闭登录界面,用户点击No后,关闭对话框,继续执行登录功能
    要求:基于属性版和基于静态成员函数版至少各用一个

    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. //添加动图
    9. QMovie *mv = new QMovie(":/picture/2310663110.gif");
    10. mv->setParent(this);
    11. ui->lab1->setMovie(mv);
    12. mv->start();
    13. ui->lab1->setScaledContents(true);
    14. //取消标题框
    15. this->setWindowFlag(Qt::FramelessWindowHint);
    16. //取消白框
    17. this->setAttribute(Qt::WA_TranslucentBackground);
    18. }
    19. Widget::~Widget()
    20. {
    21. delete ui;
    22. }
    23. void Widget::on_btn1_clicked()
    24. {//登录验证
    25. if(ui->led1->text()=="幻之"&&ui->led2->text()=="123456")
    26. {//基于静态成员函数版
    27. int res = QMessageBox::information(
    28. this,
    29. "提示",
    30. "登录成功",
    31. QMessageBox::Ok);
    32. if(res==QMessageBox::Ok)
    33. {
    34. this->close();
    35. emit sign();
    36. }
    37. }else
    38. {
    39. QMessageBox msg(//基于属性版
    40. QMessageBox::Warning,
    41. "提示",
    42. "账户和密码不匹配,是否重新登录",
    43. QMessageBox::Yes | QMessageBox::No,
    44. this);
    45. int res =msg.exec();
    46. if(res==QMessageBox::Yes)
    47. {
    48. ui->led2->setText("");
    49. }else
    50. {
    51. this->close();
    52. }
    53. }
    54. }
    55. void Widget::on_btn2_clicked()
    56. {//基于静态成员函数版
    57. int res = QMessageBox::question(
    58. this,
    59. "提示",
    60. "你是否确定要退出登录",
    61. QMessageBox::Yes | QMessageBox::No);
    62. if(res==QMessageBox::Yes)
    63. {
    64. this->close();
    65. }
    66. }

    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. this->setWindowFlag(Qt::FramelessWindowHint);
    10. //取消白框
    11. this->setAttribute(Qt::WA_TranslucentBackground);
    12. }
    13. Second::~Second()
    14. {
    15. delete ui;
    16. }
    17. void Second::sign_slot()
    18. {
    19. this->show();
    20. }

    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. Second s;
    9. QObject::connect(&w,&Widget::sign,&s,&Second::sign_slot);
    10. w.show();
    11. return a.exec();
    12. }

    第一界面

    第二界面

  • 相关阅读:
    单元测试效率优化:为什么要对程序进行测试?测试有什么好处?
    tqdm学习
    VS保存后Unity不刷新
    国内外IP线路测试网址收藏
    elementui 表格自动滚动
    常见的反爬手段和解决思路(爬虫与反爬虫)
    【Matplotlib绘制图像大全】(九):Matplotlib使用xticks()修改x轴刻度位置信息
    【工具使用-VScode】设置 VSCode 的自动保存功能
    FIFO的使用攻略(一看就会)
    配置公网和私网用户通过非公网口的IP地址访问内部服务器和Internet示例
  • 原文地址:https://blog.csdn.net/snk85k1/article/details/136242635