Reputation:
How would you get a display of dockwidgets/centralwidget in which the dockwidget in the Qt::BottomDockWidgetArea
or Qt::TopDockWidgetArea
doesn't take Qt::LeftDockWidgetArea
nor Qt::RighDockWidgetArea
space?
This is the actual display, with 2 dockwidgets and the central widget at the top right:
This would be the preferred display:
Upvotes: 7
Views: 3014
Reputation: 120608
It seems that the (slightly bizarre) trick to get this working is to set a QMainWindow as the central widget of your main window.
Here's a PyQt port of this Qt FAQ example:
from PyQt4 import QtGui, QtCore
class MainWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.setWindowTitle('Extended Side Dock Areas')
self.window = QtGui.QMainWindow(self)
self.window.setCentralWidget(QtGui.QTextEdit(self.window))
self.window.setWindowFlags(QtCore.Qt.Widget)
self.setCentralWidget(self.window)
self.dock1 = QtGui.QDockWidget(self.window)
self.dock1.setWidget(QtGui.QTextEdit(self.dock1))
self.window.addDockWidget(
QtCore.Qt.BottomDockWidgetArea, self.dock1)
self.dock2 = QtGui.QDockWidget(self)
self.dock2.setAllowedAreas(
QtCore.Qt.LeftDockWidgetArea | QtCore.Qt.RightDockWidgetArea)
self.dock2.setWidget(QtGui.QLabel('Left Dock Area', self.dock2))
self.addDockWidget(QtCore.Qt.LeftDockWidgetArea, self.dock2)
self.dock3 = QtGui.QDockWidget(self)
self.dock3.setWidget(QtGui.QLabel('Right Dock Area', self.dock3))
self.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.dock3)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
Upvotes: 3
Reputation: 717
you probably should use the QMainWindow's corner functionality to get the behavior you wanted.
Something like this may work (can't test whether its compiles, sorry):
mainWindow->setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
mainWindow->setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
mainWindow->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
mainWindow->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
See: * QMainWindow::setCorner(...)
Upvotes: 7