• QT widget


    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    int main(int argc, char* argv[])
    {
        QApplication app(argc, argv);
        // 静态标签
        QLabel *infoLabel = new QLabel;
        QLabel *openLabel = new QLabel;
        // 编辑框
        QLineEdit* cmdLineEdit = new QLineEdit;
        // 按钮
        QPushButton* cancelButton = new QPushButton;
        QPushButton* commitButton = new QPushButton;
    
        // 静态标签设置文本
        infoLabel->setText("input cmd:");
        openLabel->setText("open");
        // 按钮设置文本
        cancelButton->setText("cancel");
        commitButton->setText("commit");
    
        // 水平布局
        QHBoxLayout *cmdLayout = new QHBoxLayout;
    
        // 将openLabel和cmdLineEdit添加到水平布局中
        cmdLayout->addWidget(openLabel);
        cmdLayout->addWidget(cmdLineEdit);
    
        // 将commitButton和cacelButton按钮也添加到水平布局中
        QHBoxLayout *buttonLayout = new QHBoxLayout;
        buttonLayout->addWidget(commitButton);
        buttonLayout->addWidget(cancelButton);
    
        // 垂直布局,将几个水平布局添加到垂直布局中
        QVBoxLayout *mainLayout = new QVBoxLayout;
    
        mainLayout->addWidget(infoLabel);
        mainLayout->addLayout(cmdLayout);
        mainLayout->addLayout(buttonLayout);
    
    
        // QWidget窗口,目前有MainWndow/QWidget/QDialog
        QWidget w;
    
        // 将垂直布局和QWidget窗口进行关联
        w.setLayout(mainLayout);
        w.show(); // 显示窗口
        return app.exec(); // 事件循环
    }
    // 编译
    /**
    qmake -project
    qmake hello.pro
    mingw32-make会报错: fatal error: QApplication: No such file or directory
    需要在hello.pro最后一行加上
    QT += widgets gui
    再指向mingw32-make
    */
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
  • 相关阅读:
    数据结构--6.0最短路径
    ArangoDB 社区分布式集群 部署
    c语言必背100代码,C语言代码大全(c语言必背项目代码)
    camunda_05_integrity_architect
    jsp+sql毕业生招聘系统免费系统+论文
    提升“架构思维”?这本书值得一读!
    1720. 解码异或后的数组
    ECU Bootloader自学笔记
    Leetcode算法入门与数组丨5. 数组二分查找
    并发编程的核心问题
  • 原文地址:https://blog.csdn.net/CodeHouse/article/details/132745480