Tabify 3 QDockWidget

时间:2013-07-12 18:26:29

标签: c++ qt5 qmainwindow qdockwidget

如何在QMainWindow中为3个小部件创建一个列表化底座?

我正在使用下面的代码:

widget1 = new QDockWidget(this);
widget1 ->setObjectName("name1");
addDockWidget(Qt::LeftDockWidgetArea, widget1);
widget2 = new QDockWidget(this);
widget2 ->setObjectName("name2");
addDockWidget(Qt::LeftDockWidgetArea, widget2);
tabifyDockWidget(widget2, widget1);
widget3 = new QDockWidget(this);
widget3->setObjectName("name3");
addDockWidget(Qt::LeftDockWidgetArea, widget3);
tabifyDockWidget(widget3, widget1);

此代码产生两个停靠点:Dock 2,Dock 1和Dock 3。

1 个答案:

答案 0 :(得分:7)

要修复,我只需更改第一个和第二个参数的位置:

widget1 = new QDockWidget(this);
widget1 ->setObjectName("name1");
addDockWidget(Qt::LeftDockWidgetArea, widget1);

widget2 = new QDockWidget(this);
widget2 ->setObjectName("name2");
addDockWidget(Qt::LeftDockWidgetArea, widget2);
tabifyDockWidget(widget2, widget1);

widget3 = new QDockWidget(this);
widget3->setObjectName("name3");
addDockWidget(Qt::LeftDockWidgetArea, widget3);
tabifyDockWidget(widget1, widget3);