• Qtday3


    1. #include "widget.h"
    2. #include "ui_widget.h"
    3. Widget::Widget(QWidget *parent)
    4. : QWidget(parent)
    5. , ui(new Ui::Widget)
    6. {
    7. //窗口设置
    8. ui->setupUi(this);
    9. this->setWindowTitle("原神");
    10. this->setWindowIcon(QIcon(":/picture/genshin.png"));
    11. this->setWindowFlag(Qt::FramelessWindowHint);
    12. //标签设置
    13. QMovie *mv = new QMovie(":/picture/leishen.gif");
    14. ui->lab1->setMovie(mv);
    15. mv->start();
    16. ui->namelab->setPixmap(QPixmap(":/picture/OIP-C.jpg"));
    17. ui->namelab->resize(30, 30);
    18. ui->namelab->move(ui->naedt->x()-35, ui->naedt->y());
    19. ui->namelab->setScaledContents(true);
    20. ui->pwdlab->setPixmap(QPixmap(":/picture/suo.jpg"));
    21. ui->pwdlab->resize(30, 30);
    22. ui->pwdlab->move(ui->pwdedt->x()-35, ui->pwdedt->y());
    23. ui->pwdlab->setScaledContents(true);
    24. ui->naedt->setPlaceholderText("账号/电话/邮箱");
    25. ui->pwdedt->setPlaceholderText("密码");
    26. //按钮设置
    27. this->connect(ui->btn2, SIGNAL(clicked()), this, SLOT(my_close())); //按取消关闭窗口
    28. connect(ui->btn1, &QPushButton::clicked, this, &Widget::my_slot);
    29. }
    30. Widget::~Widget()
    31. {
    32. delete ui;
    33. }
    34. void Widget::my_slot()
    35. {
    36. if("admin" == ui->naedt->text() && "123456" == ui->pwdedt->text())
    37. {
    38. //创建消息对话框
    39. int ret = QMessageBox::information(this, "提示", "登录成功", QMessageBox::Ok);
    40. if(QMessageBox::Ok == ret)
    41. {
    42. emit Jump(); //登陆成功点击ok跳转
    43. this->close();
    44. }
    45. }
    46. else
    47. {
    48. //基于属性创建错误信息框
    49. QMessageBox msg(
    50. QMessageBox::Critical,
    51. "错误",
    52. "帐号和密码不匹配,是否重新登录?",
    53. QMessageBox::Yes | QMessageBox::No,
    54. this);
    55. int ret = msg.exec(); // 基于属性创建的信息对话框需要执行exec函数才能生成对话框
    56. if(QMessageBox::Yes == ret)
    57. {
    58. ui->pwdedt->clear(); //Yes清空密码
    59. }
    60. else
    61. {
    62. this->close(); //NO关闭窗口
    63. }
    64. }
    65. }
    66. void Widget::my_close()
    67. {
    68. //创建问题对话框
    69. int ret = QMessageBox::question(this, "问题", "是否退出登录?", QMessageBox::Yes | QMessageBox::No);
    70. if(QMessageBox::Yes == ret)
    71. {
    72. this->close(); //Yes退出登录界面
    73. }
    74. }
    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::my_slot()
    14. {
    15. this->show();
    16. }
    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. //连接两个窗口
    11. QObject::connect(&w, &Widget::Jump, &s, &Second::my_slot);
    12. return a.exec();
    13. }

  • 相关阅读:
    运维实践-最新Nginx二进制构建编译lua-nginx-module动态链接Lua脚本访问Redis数据库读取静态资源隐式展现
    Android 12.0 系统wifi列表显示已连接但无法访问网络问题解决
    LeetCode--215. 数组中的第K个最大元素(C++描述)
    学生成绩管理程序: 用面向对象的方法
    【JavaEE】JVM 剖析
    暴力递归转动态规划(八)
    分享2022上半年我读过的7本书
    【微服务】微服务开发与注册----Eureka Client
    failed to parse field [name] of type [text] in document with id ‘1‘
    一次springboot和redis缓存的实践
  • 原文地址:https://blog.csdn.net/darkestdying/article/details/133933612