安安你好  
 
#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();
}



安安你好_2  

#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()));//按下按鈕關閉程式
 
    //LabelButton加入垂直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();
}
 
 
 
arrow
arrow
    全站熱搜

    黃彥霖 發表在 痞客邦 留言(0) 人氣()