在QMainWindow中添加孩子

anj*_*anj 7 qt4 qmainwindow

如何Widget在相等的部分添加两个子对象QMainWindow.

MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent)

{   TreeArea *ta= new TreeArea(this);
    TreeArea *ta1= new TreeArea(this);
.
.
.
  TreeArea::TreeArea(QWidget *parent) :
 QWidget(parent)
{
.
.
.
Run Code Online (Sandbox Code Playgroud)

Neo*_*eox 14

因为电子锌建议你必须使用布局.假设您要在主窗口中插入两个小部件.

QHBoxLayout *layout = new QHBoxLayout;

QPushButton *button1 = new QPushButton("button1");
QPushButton *button2 = new QPushButton("button2");

layout->addWidget(button1);
layout->addWidget(button2);

setCentralWidget(new QWidget);
centralWidget()->setLayout(layout);
Run Code Online (Sandbox Code Playgroud)

这将水平布局小部件,您将得到以下结果: QHBoxLayoutExample

如果你想垂直布局它们使用 QVBoxLayout

我强烈建议阅读文档.Qt中的布局管理


Hai*_* Li 5

使用QMainWindow::setCentralWidget(QWidget *)添加自己的控制。