• qt day


    1. #include "widget.h"
    2. #include "ui_widget.h"
    3. void Widget::my_slot()
    4. {
    5. }
    6. Widget::Widget(QWidget *parent)
    7. : QWidget(parent)
    8. , ui(new Ui::Widget)
    9. {
    10. ui->setupUi(this);
    11. this->setWindowIcon(QIcon(":/wodepeizhenshi.png"));//設置窗口的icon
    12. this->setWindowTitle("鵬哥快聊");//更改名字
    13. this->setFixedSize(500,400);//設置尺寸
    14. QLabel *ql=new QLabel(this);//創建一個標簽
    15. ql->resize(QSize(500,200));//設置標簽大小
    16. ql->setPixmap(QString(":/logo.png"));
    17. ql->setScaledContents(true);
    18. QLabel *ql1=new QLabel(this);//創建一個標簽
    19. QLabel *ql2=new QLabel(this);//創建一個標簽
    20. edit1= new QLineEdit(this);//創建一個行編輯器
    21. edit2= new QLineEdit(this);//創建一個行編輯器
    22. edit1->resize(200,40);//為含編輯器設置尺寸
    23. edit2->resize(200,40);
    24. edit1->move(270,230);//含編輯器的位置
    25. edit2->move(edit1->x(),edit1->y()+50);
    26. edit1->setPlaceholderText("QQ/手機/郵箱");//設置展位文本
    27. edit2->setPlaceholderText("密碼");
    28. edit2->setEchoMode(QLineEdit::Password);//設置囘顯模式
    29. ql1->resize(40,40);//設置標簽的大小
    30. ql2->resize(40,40);
    31. ql1->move(210,edit1->y());
    32. ql2->move(210,edit2->y());
    33. ql1->setPixmap(QString(":/userName.jpg"));
    34. ql2->setPixmap(QString(":/passwd.jpg"));
    35. ql1->setScaledContents(true);
    36. ql2->setScaledContents(true);
    37. //創建兩個按鈕用輸入賬號密碼
    38. QPushButton *btn1= new QPushButton(this);
    39. QPushButton *btn2= new QPushButton(this);
    40. btn1->resize(QSize(70,40));//設置按鈕的大小
    41. btn2->resize(btn1->size());
    42. btn1->move(300,360);//按鈕位置
    43. btn2->move(btn1->x()+80,btn1->y());
    44. btn1->setText("登錄");
    45. btn2->setText("取消");
    46. btn1->setIcon(QIcon(":/login.png"));//導入按鈕圖片
    47. btn2->setIcon(QIcon(":/cancel.png"));
    48. connect(btn1,&QPushButton::clicked,this,&Widget::fun);
    49. connect(btn2,&QPushButton::clicked,this,&Widget::fun1);
    50. }
    51. void Widget::fun()
    52. {
    53. if(this->edit1->text()=="admin"&&this->edit2->text()=="123456")
    54. {
    55. qDebug()<<"deng lu cheng gong";
    56. emit jump();//跳转信号
    57. this->close();//关闭界面
    58. }
    59. else
    60. {
    61. qDebug()<<"deng lu shi bai";
    62. Widget::edit2->clear();
    63. }
    64. }
    65. void Widget::fun1()
    66. {
    67. this->close();
    68. }
    69. Widget::~Widget()
    70. {
    71. delete ui;
    72. }
    1. #include "widget.h"
    2. #include "form.h"
    3. #include
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. Widget w;
    8. w.show();
    9. Form f;
    10. Widget::connect(&w,&Widget::jump,&f,&Form::jump_slot);
    11. return a.exec();
    12. }
    1. #include "form.h"
    2. #include "ui_form.h"
    3. Form::Form(QWidget *parent) :
    4. QWidget(parent),
    5. ui(new Ui::Form)
    6. {
    7. ui->setupUi(this);
    8. }
    9. void Form::jump_slot()
    10. {
    11. this->show();
    12. }
    13. Form::~Form()
    14. {
    15. delete ui;
    16. }
    1. #ifndef WIDGET_H
    2. #define WIDGET_H
    3. #include
    4. #include
    5. #include
    6. #include
    7. #include
    8. QT_BEGIN_NAMESPACE
    9. namespace Ui { class Widget; }
    10. QT_END_NAMESPACE
    11. class Widget : public QWidget
    12. {
    13. Q_OBJECT
    14. signals:
    15. void my_signal();//自定义信号
    16. void jump();//用于跳转信号
    17. public slots:
    18. void my_slot();//自定义槽函数
    19. void fun();
    20. void fun1();
    21. public:
    22. Widget(QWidget *parent = nullptr);
    23. ~Widget();
    24. private:
    25. Ui::Widget *ui;
    26. QLineEdit *edit1;
    27. QLineEdit *edit2;
    28. };
    29. #endif // WIDGET_H

  • 相关阅读:
    国际化组件
    澳元兑美元预测:美元可能因美国经济衰退担忧而进一步下跌(MogaFX)
    【云原生】-Docker容器迁移Oracle到MySQL
    【QT学习】8.qt事件处理机制,事件过滤器,自定义事件
    【五】Socket函数详解
    FPGA 学习笔记:Vivado 2018.2 MicroBlaze Uartlite 配置
    MySQL报错:Row size too large。
    MySQL数据库的日志管理
    Shiro之保存Session到数据库中-yellowcong
    谈谈Selenium中浏览器驱动的日志
  • 原文地址:https://blog.csdn.net/qilitolxx/article/details/132609761