#include<QApplication>
#include<QLabel>
intmain(intargc,char*argv[]) {
QApplicationa(argc,argv);
QWidget*w=newQWidget();
QLabeltxt(w);
txt.setText("世界你好");
w->setWindowTitle("安安你好");
w->setMinimumWidth(300);
w->setMinimumHeight(200);
w->show();
returna.exec();
}
#include<QApplication>
#include<QLabel>
#include<QVBoxLayout>
#include<QPushButton>
intmain(intargc,char*argv[]){
QApplicationa(argc,argv);
QWidget*w=newQWidget();
//建立文字(Label)
QLabeltxt(w);
txt.setText("世界你好");
//建立按鈕(Button)
QPushButton*b=newQPushButton(QObject::tr("關閉拉"),w);
QObject::connect(b,SIGNAL(clicked()),w,SLOT(close()));//按下按鈕關閉程式
//將Label與Button加入垂直Layout中
QVBoxLayout*layout=newQVBoxLayout;
layout->addWidget(&txt);
layout->addWidget(b);
//Layout加入Widget中
w->setLayout(layout);
//設定:視窗標題、大小
w->setWindowTitle("安安你好");
w->setMinimumWidth(300);
w->setMinimumHeight(200);
//顯示視窗
w->show();
returna.exec();
}
全站熱搜
留言列表