Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding child in QMainWindow

How can i add two child Widget objects in equal portion of QMainWindow.

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

{   TreeArea *ta= new TreeArea(this);
    TreeArea *ta1= new TreeArea(this);
.
.
.
  TreeArea::TreeArea(QWidget *parent) :
 QWidget(parent)
{
.
.
.
like image 956
anj Avatar asked Feb 15 '12 09:02

anj


2 Answers

As e-zinc suggested you have to use layout. Say you want to insert two widgets into the mainwindow.

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);

This will layout widgets horizontally and you will get this result: QHBoxLayoutExample

And if you want to layout them vertically use QVBoxLayout

I would strongly suggest reading the documentation. Layout Management in Qt

like image 127
Neox Avatar answered Sep 20 '22 04:09

Neox


Use QMainWindow::setCentralWidget(QWidget *) to add your own control.

like image 38
Haiyuan Li Avatar answered Sep 17 '22 04:09

Haiyuan Li