• QT day03


    思维导图

    QT设计

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

    要求: 1. qss实现

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

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

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

    代码:

    main.cpp

    1. #include "widget.h"
    2. #include
    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. //将w的信号函数和s的槽函数连接
    11. QObject::connect(&w, &Widget::signal_jump, &s, &Second::slot_jump);
    12. return a.exec();
    13. }

    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::slot_jump()
    14. {
    15. this->show(); //显示自身界面
    16. }

    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. this->setWindowFlag(Qt::FramelessWindowHint);
    10. //去掉空白部分
    11. this->setAttribute(Qt::WA_TranslucentBackground);
    12. }
    13. Widget::~Widget()
    14. {
    15. delete ui;
    16. }
    17. void Widget::on_pushButton_clicked()
    18. {
    19. //获取username信息
    20. QString uname = ui->lineEdit->text();
    21. //获取密码信息
    22. QString passwd = ui->lineEdit_2->text();
    23. //验证账号密码是否正确
    24. if(uname == "admin" && passwd == "123456")
    25. {
    26. this->close(); //关闭自身界面
    27. emit signal_jump(); //触发信号函数 跳转到另一个界面
    28. }else
    29. {
    30. //弹框提示
    31. QMessageBox *mbox1 = new QMessageBox
    32. (QMessageBox::Information
    33. ,"提示"
    34. ,"账号或密码错误"
    35. ,QMessageBox::Ok);
    36. //按下弹框的ok按钮,清空密码框中内容
    37. if(mbox1->exec() == QMessageBox::Ok)
    38. ui->lineEdit_2->clear();
    39. }
    40. }
    41. void Widget::on_pushButton_2_clicked()
    42. {
    43. this->close();
    44. }

    widget.ui

    编辑样式表

    1. *{
    2. background-color: rgb(255, 255, 255);
    3. }
    4. QFrame#frame{
    5. border-image: url(:/Logo/shanChuan.jpg);
    6. border-radius:15px;
    7. }
    8. #frame_2{
    9. background-color: rgba(110, 110, 110, 120);
    10. border-radius:15px;
    11. }
    12. QLabel#label{
    13. background-color: rgba(80, 80, 80, 120);
    14. border-radius:30px;
    15. }
    16. #label_2{
    17. background:transparent; /* 完全透明*/
    18. font: 16pt "等线";
    19. color: rgba(255, 255, 255, 120);
    20. }
    21. QLineEdit{
    22. background:transparent; /* 完全透明*/
    23. border:none; /* 设置无边框*/
    24. border-bottom:1px solid rgba(255, 255, 255, 120); /*设置下边框 1像素 实线 背景颜色*/
    25. color: rgba(255, 255, 255, 120);
    26. font: 14pt "等线";
    27. }
    28. QPushButton#pushButton{
    29. color: rgba(255, 255, 255, 120);
    30. font: 14pt "等线";
    31. background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(111, 111, 255, 255), stop:1 rgba(255, 255, 255, 255));
    32. border-radius:5px;
    33. }
    34. #pushButton_2{ /* 关闭按钮*/
    35. color: rgba(255, 255, 255, 120);
    36. background:transparent; /* 完全透明*/
    37. border-radius:10px;
    38. }
    39. #pushButton_3{ /*最小化按钮*/
    40. color: rgba(255, 255, 255, 120);
    41. background:transparent; /* 完全透明*/
    42. border-radius:10px;
    43. }
    44. QPushButton#pushButton:hover{ /* 鼠标移动 背景颜色有变化*/
    45. color: rgba(255, 255, 255, 120);
    46. font: 14pt "等线";
    47. background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(150, 111, 255, 255), stop:1 rgba(255, 255, 255, 255));
    48. border-radius:5px;
    49. }
    50. #pushButton_2:hover{ /* 鼠标移动 背景颜色变红色*/
    51. background-color: rgb(65, 65, 65);
    52. color: rgba(255, 255, 255, 120);
    53. border-radius:15px;
    54. }
    55. #pushButton_3:hover{ /* 鼠标移动 背景颜色变红色*/
    56. background-color: rgb(65, 65, 65);
    57. color: rgba(255, 255, 255, 120);
    58. border-radius:15px;
    59. }
    60. QPushButton#pushButton:pressed{ /*鼠标按下操作 字体抖动*/
    61. color: rgba(255, 255, 255, 120);
    62. font: 14pt "等线";
    63. background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(111, 111, 255, 255), stop:1 rgba(255, 255, 255, 255));
    64. border-radius:5px;
    65. padding-top:5px;
    66. padding-left:5px;
    67. }
    68. #pushButton_2:pressed{
    69. border-radius:15px;
    70. padding-top:5px;
    71. padding-left:5px;
    72. }
    73. #pushButton_3:pressed{
    74. border-radius:15px;
    75. padding-top:5px;
    76. padding-left:5px;
    77. }

    运行结果:

  • 相关阅读:
    Day693.Tomcat如何实现Servlet规范 -深入拆解 Tomcat & Jetty
    CockroachDB-读和写
    redis 常用方法
    .net 微服务 服务保护 自动重试 Polly
    数据校验JSR303入门实践
    RedisHttpSession反序列化UID问题跟踪
    PHP如何持续监听Redis的消息订阅并推送到前端?
    源码:Infragistics 2022.2 sources
    37、CSS进阶——堆叠上下文及z-index
    基于java的毕业设计选题双选系统
  • 原文地址:https://blog.csdn.net/SweetDvil/article/details/139753358