[PyQt] How to make dock widgets fill space
Dan Davison
davison at stats.ox.ac.uk
Mon Aug 17 13:03:53 BST 2009
A beginners question. The code below sets up a main window with two dock
widgets (which themselves contain tree/list widgets). However, when it
starts up, there is an empty area between the two dock widgets (one is
above, and one below). What is the correct way to set this up so that
the two dock widgets expand vertically to fill all the space? (The
commented out setMaximumSize calls didn't seem to have any effect).
Thanks,
Dan
#!/usr/bin/env python
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.mainWidget = QWidget()
self.setCentralWidget(self.mainWidget)
tdw = QDockWidget("top dock widget", self)
tdw.setAllowedAreas(Qt.TopDockWidgetArea)
tw = QTreeWidget()
tdw.setWidget(tw)
self.addDockWidget(Qt.TopDockWidgetArea, tdw)
# dw.setMaximumSize(dw.maximumSize())
bdw = QDockWidget("bottom dock widget", self)
bdw.setAllowedAreas(Qt.BottomDockWidgetArea)
lw = QListWidget()
bdw.setWidget(lw)
self.addDockWidget(Qt.BottomDockWidgetArea, bdw)
# ldw.setMaximumSize(ldw.maximumSize())
if __name__ == '__main__':
app = QApplication(sys.argv)
mainWindow = MainWindow()
mainWindow.show()
app.exec_()
More information about the PyQt
mailing list