qt作业2

[复制链接]
发表于 2025-11-17 22:02:25 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
  1. #ifndef FAILURE_H
  2. #define FAILURE_H
  3. #include <QWidget>
  4. #include <QTimer>
  5. namespace Ui {
  6. class failure;
  7. }
  8. class failure : public QWidget
  9. {
  10.     Q_OBJECT
  11. public:
  12.     explicit failure(QWidget *parent = nullptr);
  13.     ~failure();
  14. public slots:
  15. void failure_slot();
  16. private:
  17.     Ui::failure *ui;
  18. };
  19. #endif // FAILURE_H
复制代码
  1. #ifndef SUCCESS_H
  2. #define SUCCESS_H
  3. #include <QWidget>
  4. namespace Ui {
  5. class Success;
  6. }
  7. class Success : public QWidget
  8. {
  9.     Q_OBJECT
  10. public:
  11.     explicit Success(QWidget *parent = nullptr);
  12.     ~Success();
  13. signals:
  14. void my_return();
  15. public slots:
  16. void Login_success();
  17. private slots:
  18. void on_pushButton_clicked();
  19. private:
  20.     Ui::Success *ui;
  21. };
  22. #endif // SUCCESS_H
复制代码
  1. #ifndef WIDGET_H
  2. #define WIDGET_H
  3. #include <QWidget>
  4. #include <QTimer>
  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_login();
  16. void my_failure();
  17. public slots:
  18. void return_slot();
  19. private slots:
  20. void on_pushButton_clicked();
  21. void on_pushButton_2_clicked();
  22. private:
  23.     Ui::Widget *ui;
  24. };
  25. #endif // WIDGET_H
复制代码
  1. #include "failure.h"
  2. #include "ui_failure.h"
  3. failure::failure(QWidget *parent) :
  4.     QWidget(parent),
  5.     ui(new Ui::failure)
  6. {
  7.     ui->setupUi(this);
  8.     //去掉头部
  9.     this->setWindowFlag(Qt::FramelessWindowHint);
  10.     //去掉组件空白部分
  11.     this->setAttribute(Qt::WA_TranslucentBackground);
  12. }
  13. failure::~failure()
  14. {
  15.     delete ui;
  16. }
  17. void failure::failure_slot()
  18. {
  19.     this->show();
  20.     QTimer::singleShot(600,this,[this]()
  21.     {
  22.         this->close();
  23.     });
  24. }
复制代码
  1. #include "widget.h"
  2. #include <QApplication>
  3. #include "success.h"
  4. #include "failure.h"
  5. int main(int argc, char *argv[])
  6. {
  7.     QApplication a(argc, argv);
  8.     Widget w;
  9.     w.show();
  10.     Success s;
  11.     failure f;
  12.     QObject::connect(&w,&Widget::my_login,&s,&Success::Login_success);
  13.     QObject::connect(&s,&Success::my_return,&w,&Widget::return_slot);
  14.     QObject::connect(&w,&Widget::my_failure,&f,&failure::failure_slot);
  15.     return a.exec();
  16. }
复制代码
  1. #include "success.h"
  2. #include "ui_success.h"
  3. Success::Success(QWidget *parent) :
  4.     QWidget(parent),
  5.     ui(new Ui::Success)
  6. {
  7.     ui->setupUi(this);
  8.     //去掉头部
  9.     this->setWindowFlag(Qt::FramelessWindowHint);
  10. }
  11. Success::~Success()
  12. {
  13.     delete ui;
  14. }
  15. void Success::Login_success()
  16. {
  17.     this->show();
  18. }
  19. void Success::on_pushButton_clicked()
  20. {
  21.     emit my_return();
  22.     this->close();
  23. }
复制代码
  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::return_slot()
  18. {
  19.     this->show();
  20. }
  21. void Widget::on_pushButton_clicked()
  22. {
  23.     if(ui->lineEdit->text()=="admin"&&ui->lineEdit_2->text()=="123456")
  24.     {
  25.     emit my_login();
  26.     this->close();
  27.     }
  28.     else
  29.     {
  30.         ui->lineEdit_2->setText("");
  31.             emit my_failure();
  32.     }
  33. }
  34. void Widget::on_pushButton_2_clicked()
  35. {
  36.     ui->lineEdit->setText("");
  37.     ui->lineEdit_2->setText("");
  38. }
复制代码
  1. *{
  2.         background-color: rgb(255, 255, 255);
  3.         border-radius:30px;
  4. }
  5. QFrame#frame{
  6.        
  7.         background-color: qconicalgradient(cx:0.5, cy:0.5, angle:0, stop:0 rgba(0, 255, 255, 255), stop:0.373979 rgba(255, 255, 255, 255), stop:0.373991 rgba(33, 30, 255, 255), stop:0.624018 rgba(33, 30, 255, 255), stop:0.624043 rgba(255, 0, 0, 255), stop:1 rgba(255, 0, 0, 255));
  8.         border-image: url(:/Logo/shangHai.jpg);
  9.         border-radius:30px;
  10.        
  11. }
  12. #frame_2{
  13.        
  14.         background-color: rgba(130, 130, 130, 100);
  15.         border-radius:30px;
  16. }
  17. QLabel#label{
  18.         background-color: rgba(154, 154, 154, 100);
  19.         border-radius:30px;
  20. }
  21. QLabel#label_2{
  22.         font: 20pt "楷体";
  23.         border-radius:30px;
  24.         background-color: rgba(255, 255, 255, 0);
  25.         color: rgba(255, 255, 255, 150);
  26. }
  27. QLineEdit#lineEdit
  28. {
  29.         background:transparent;
  30.         border:none;
  31.         border-bottom:1px solid rgba(255,255,255,150);
  32.         color: rgba(255, 255, 255, 150);
  33. }
  34. QLineEdit#lineEdit_2
  35. {
  36.         background:transparent;
  37.         border:none;
  38.         border-bottom:1px solid rgba(255,255,255,150);
  39.         color: rgba(255, 255, 255, 150);
  40. }
  41. QLineEdit#lineEdit_3
  42. {
  43.         background:transparent;
  44.         border:none;
  45.         border-bottom:1px solid rgba(255,255,255,150);
  46. }
  47. QPushButton#pushButton
  48. {
  49.         border-radius:10px;
  50.         color: rgba(255, 255, 255, 150);
  51.        
  52.         background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(0, 145, 171, 255), stop:1 rgba(255, 255, 255, 255));
  53. }
  54. QPushButton#pushButton:hover
  55. {
  56.         border-radius:10px;
  57.         color: rgba(255, 255, 255, 150);
  58.        
  59.         background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(0, 185, 171, 255), stop:1 rgba(255, 255, 255, 255));
  60. }
  61. QPushButton#pushButton:pressed
  62. {
  63.         border-radius:10px;
  64.         color: rgba(255, 255, 255, 150);
  65.        
  66.         background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(0, 145, 171, 255), stop:1 rgba(255, 255, 255, 255));
  67.         padding-top:5px;
  68. }
  69. QPushButton#pushButton_2
  70. {
  71.         border-radius:10px;
  72.         color: rgba(255, 255, 255, 150);
  73.        
  74.         background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(0, 145, 171, 255), stop:1 rgba(255, 255, 255, 255));
  75. }
  76. QPushButton#pushButton_2:hover
  77. {
  78.         border-radius:10px;
  79.         color: rgba(255, 255, 255, 150);
  80.        
  81.         background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(0, 185, 171, 255), stop:1 rgba(255, 255, 255, 255));
  82. }
  83. QPushButton#pushButton_2:pressed
  84. {
  85.         border-radius:10px;
  86.         color: rgba(255, 255, 255, 150);
  87.        
  88.         background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(0, 145, 171, 255), stop:1 rgba(255, 255, 255, 255));
  89.         padding-top:5px;
  90. }
  91. QPushButton#pushButton_3
  92. {
  93.         border-radius:10px;
  94.         color: rgba(255, 255, 255, 150);
  95.        
  96.         background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(0, 145, 171, 255), stop:1 rgba(255, 255, 255, 255));
  97. }
  98. QPushButton#pushButton_3:hover
  99. {
  100.         border-radius:10px;
  101.         color: rgba(255, 255, 255, 150);
  102.        
  103.         background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(0, 185, 171, 255), stop:1 rgba(255, 255, 255, 255));
  104.    
  105. }
复制代码

输入账号暗码,账号暗码正确,登录乐成

关掉本界面,弹出下一个界面,点击返回回到刚才的界面

如果账号暗码错误,则弹出登录失败,6秒后消散


回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表