您的位置:首页 > 编程语言 > Qt开发

QT中在MainWindow中代码添加控件

2015-12-04 16:14 981 查看
感谢 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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: