1.创建一个空的QT工程文件
2 建立程序文件
MainWindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H #include<QMainWindow> class MainWindow : public QMainWindow{
Q_OBJECT
public:
MainWindow();
}; #endif // MAINWINDOW_H
MainWindow.cpp
#include<QtGui>
#include"MainWindow.h" MainWindow::MainWindow(){
QWidget *widget=new QWidget;
setCentralWidget(widget); QWidget *topfiller=new QWidget;
topfiller->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); QWidget *bottomFiller=new QWidget;
bottomFiller->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); QVBoxLayout *layout=new QVBoxLayout;
layout->addWidget(topfiller);
layout->addWidget(bottomFiller);
widget->setLayout(layout); setWindowTitle(tr("Main Window"));
resize(512,480); }
Main.cpp
#include<QApplication>
#include"MainWindow.h" int main(int argc,char* argv[]){
QApplication app(argc,argv);
MainWindow wnd;
wnd.show();
app.exec(); }