//mywidget.cpp
#include "mywidget.h"
#include <QPushButton>
MyWidget::MyWidget(QWidget *parent)
: QWidget(parent)
{
#if 1
//創建第一個按鈕
QPushButton *btn = new QPushButton;
//btn->show(); //show是以頂層方式來彈出窗口控件
//讓btn依附在myWidget窗口中
btn->setParent(this);
//顯示文本
//btn->setText("第一個按鈕");
btn->setText("First button");
#endif
//創建第二個按鈕 這種構造方式,會按照控件的大小創建了MyWidget窗口
QPushButton *btn2 = new QPushButton("Second button", this); //字符串會自動轉換為QString
//移動btn按鈕
btn2->move(100, 100);
//重置窗口的大小
resize(600, 400);
//設置固定窗口的大小
setFixedSize(600, 400);
//設置窗口的標題
setWindowTitle("First Window");
}
MyWidget::~MyWidget()
{
}