Issue
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. QDockWidget("File System Viewer"). Is there an easy, current way to add more dock locations instead of a single central widget? This thread suggests it was once available but is not recommended now. If not, is there a way to label the central widget so it looks like the docks?
Solution
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_())
Answered By - ekhumoro
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.