QT gui demo

  • Demo2.h

#ifndef DEMO2_H
#define DEMO2_H
 
#include <QWidget>
 
class QLabel;
class QPushButton;
class QCheckBox;
class QRadioButton;
class QLineEdit;
 
// Demo2 繼承自 QWidget
class Demo2 : public QWidget {
    Q_OBJECT
 
public:
    Demo2(QWidget *parent = 0);
 
private:
    QLabel *b1;
    QPushButton *b2;
    QCheckBox *b3;
    QRadioButton *b4;
    QLineEdit *b5;
};
 
#endif

  • Demo2.cpp

#include <QtGui>
#include "Demo2.h"
 
Demo2::Demo2(QWidget *parent) : QWidget(parent) {
    // 將成員變數屬性初始化
    b1 = new QLabel(tr("QLabel"));
    b2 = new QPushButton(tr("QPushButton"));
    b3 = new QCheckBox(tr("QCheckBox"));
    b4 = new QRadioButton(tr("QRadioButton"));
    b5 = new QLineEdit;
     
    // 建立版面樣式物件
    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(b1);
    layout->addWidget(b2);
    layout->addWidget(b3);
    layout->addWidget(b4);
    layout->addWidget(b5);
     
    // 設定版面樣式與視窗標題
    setLayout(layout);
    setWindowTitle(tr("Demo2"));
}

  • main.cpp

#include <QtGui>
#include "Demo2.h"
 
int main(int argv, char **args)
{
    QApplication app(argv, args);
 
    Demo2 demo;
    demo.show();
 
    return app.exec();
}

效果:




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值