Reputation: 1045
I have a class which inherits from QMainWindow
. In the constructor, I set the Central Widget
to NULL
and then add several QDockWidgets
to make a user interface which consits of QDockWidgets
only:
UserWidget::UserWidget(QWidget * parent) : QMainWindow(parent)
{
this->setCentralWidget(NULL);
// create Widgets for User communication e.g. PushButtons etc.
// ...
dockWidget_ = new QDockWidget;
dockWidget->setAllowedAreas(Qt::AllDockWidgetAreas);
dockWidget->setWidget(userWidget_);
this->addDockWidget(Qt::RightDockWidgetArea);
Now I add another QDockWidget but instead of Qt::RightDockWidgetArea
, I choose Qt::LeftDockWidgetArea
:
dockWidget_ = new QDockWidget;
dockWidget->setAllowedAreas(Qt::AllDockWidgetAreas);
dockWidget->setWidget(userWidget2_);
this->addDockWidget(Qt::LeftDockWidgetArea);
Up to here, the appearance of my program is similar to this:
Proceeding further with adding another QDockWidget
:
dockWidget_ = new QDockWidget;
dockWidget->setAllowedAreas(Qt::AllDockWidgetAreas);
dockWidget->setWidget(userWidget3_);
this->addDockWidget(Qt::LeftDockWidgetArea /* or Qt::RightDockWidgetArea*/);
I end up with one of the area splitted in the middle :
But I want to split the layout into 3 columns, similar to:
However, I did not find any suitable way to do this. Setting the area to Qt::TopDockWidgetArea
or Qt::BottomDockWidgetArea
neither provides the desired behavior. I would really appreciate any help here.
Upvotes: 2
Views: 1996
Reputation: 4125
You just have to use the function splitDockWidget() :
void QMainWindow::splitDockWidget(QDockWidget *first, QDockWidget *second, Qt::Orientation orientation)
In your case, you can put one QDockWidget
(let's call him dock1
) on the left and the other two on the right (dock2
and dock3
) and the call the function like this :
splitDockWidget(dock2, dock3, Qt::Horizontal);
Upvotes: 4