QT中在MainWindow中代码添加控件

感谢 http://blog.csdn.net/noodle123/article/details/8260693

代码如下:

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QRadioButton *radio1 = new QRadioButton(tr("&Radio button 1"));
    QVBoxLayout *vbox = new QVBoxLayout(this);
    vbox->addWidget(radio1);
    QWidget *centerWindow = new QWidget(this);
    this->setCentralWidget(centerWindow);
    centerWindow->setLayout(vbox);
}


Note: Creating a main window without a central widget is not supported. You must 
have a central widget even if it is just a placeholder.

QWidget   * centerWindow   =   new   QWidget ;
    this->setCentralWidget(centerWindow);
    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(splitter);
    centerWindow->setLayout(mainLayout);


你可能感兴趣的:(qt)