How can I position QDockWidgets when code is displayed on the screen?

I want the Qt window to appear using the following dock widget layout on the right.

alt text http://img72.imageshack.us/img72/6180/docksonside.png

Qt allows you to specify the addDockWidget argument of the QMainWindow method to indicate the position (top, bottom, left, or right), but apparently two QDockWidgets placed on one side will not be placed.

Here is the code that adds the dock widgets. this uses PyQt4, but it should be the same for Qt with C ++

 self.memUseGraph = mem_use_widget(self) self.memUseDock = QDockWidget("Memory Usage") self.memUseDock.setObjectName("Memory Usage") self.memUseDock.setWidget(self.memUseGraph) self.addDockWidget(Qt.DockWidgetArea(Qt.RightDockWidgetArea),self.memUseDock) self.diskUsageGraph = disk_usage_widget(self) self.diskUsageDock = QDockWidget("Disk Usage") self.diskUsageDock.setObjectName("Disk Usage") self.diskUsageDock.setWidget(self.diskUsageGraph) self.addDockWidget(Qt.DockWidgetArea(Qt.RightDockWidgetArea),self.diskUsageDock) 

When this code is used to add both of them to the right side, one above the other, and not as a captured screenshot. The way I took this shot was to drag them there with the mouse after starting the program, but I need this to start.

+4
source share
2 answers

I have never tried, but I think you can set the orientation of the dock widget by adding it to the main window:

void QMainWindow::addDockWidget ( Qt::DockWidgetArea area, QDockWidget * dockwidget, Qt::Orientation orientation )

+5
source

You can use QMainWindow :: splitDockWidget .

From the docs:

Divides the space covered by the first dock widget into two parts, moves the first dock widget to the first part and moves the second dock widget to the second part.

Orientation determines the separation of space: Qt :: Horizontal split places the second dock widget to the right of the first; Qt :: Vertical split places the second dock widget below the first.

You should set QMainWindow :: dockNestingEnabled to true (but I think you already did it).

+7
source

Source: https://habr.com/ru/post/1312333/


All Articles