How can I position QDockWidgets as the screen shot shows using code?

Posted by Nathan on Stack Overflow See other posts from Stack Overflow or by Nathan
Published on 2010-06-09T13:48:58Z Indexed on 2010/06/09 13:52 UTC
Read the original article Hit count: 235

Filed under:
|
|
|
|

I want a Qt window to come up with the following arrangement of dock widgets on the right.

alt text

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

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 is above the other, not like the screen shot I made. The way I made that shot was to drag them there with the mouse after starting the program, but I need it to start that way.

© Stack Overflow or respective owner

Related posts about design

Related posts about gui