Skip to content Skip to sidebar Skip to footer

More Dock Locations Using PySide?

I like the dock analogy and believe users may want two large 'central' widgets as well as the top, bottom, and side widgets. I also like that the dock widgets are labeled, e.g. QDo

Solution 1:

The answer you linked to already provides a solution, which is to set a QMainWindow as the central widget. This central widget must only have dock widgets, and no central widget of its own.

There are a few limitations to this approach. Firstly, the central dock-widgets cannot be interchanged with the outer dock-widgets (and vice-versa). Secondly, if all the outer dock-widgets are closed, there will no way to restore them unless the main-window has a menu-bar. The menu-bar automatically provides a context menu for restoring dock-widgets. This is the same menu that is shown when right-clicking a dock-widget title-bar.

Here is a demo script that demonstrates this approach:

import sys
from PySide import QtGui, QtCore

class MainWindow(QtGui.QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.centre = QtGui.QMainWindow(self)
        self.centre.setWindowFlags(QtCore.Qt.Widget)
        self.centre.setDockOptions(
            QtGui.QMainWindow.AnimatedDocks |
            QtGui.QMainWindow.AllowNestedDocks)
        self.setCentralWidget(self.centre)
        self.dockCentre1 = QtGui.QDockWidget(self.centre)
        self.dockCentre1.setWindowTitle('Centre 1')
        self.centre.addDockWidget(
            QtCore.Qt.LeftDockWidgetArea, self.dockCentre1)
        self.dockCentre2 = QtGui.QDockWidget(self.centre)
        self.dockCentre2.setWindowTitle('Centre 2')
        self.centre.addDockWidget(
            QtCore.Qt.RightDockWidgetArea, self.dockCentre2)
        self.dockLeft = QtGui.QDockWidget(self)
        self.dockLeft.setWindowTitle('Left')
        self.addDockWidget(QtCore.Qt.LeftDockWidgetArea, self.dockLeft)
        self.dockRight = QtGui.QDockWidget(self)
        self.dockRight.setWindowTitle('Right')
        self.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.dockRight)
        self.menuBar().addMenu('File').addAction('Quit', self.close)

if __name__ == '__main__':

    app = QtGui.QApplication(sys.argv)
    window = MainWindow()
    window.setGeometry(500, 50, 600, 400)
    window.show()
    sys.exit(app.exec_())

Post a Comment for "More Dock Locations Using PySide?"