最近,一次编程中,我发现在mainwindow中布局是不能正常显示的,这让我伤透了脑筋,为什么不可以呢?又该怎么在mainwindow中对控件进行布局呢?
百度是最好的 老师。我在百度上找到了最后的解决方法,就是在mainwindow中定义一个widget 之后,除了菜单栏,状态栏,工具栏之外,所有的控件都放在widget中。
下面见代码:
QWidget *centerWindow = new QWidget;
this->setCentralWidget(centerWindow);
button = new QPushButton("One");
button2 = new QPushButton("Two");
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(button);
layout->addWidget(button2);
centerWindow-