Trouble getting QMainWindow to scroll
Posted
by
random
on Stack Overflow
See other posts from Stack Overflow
or by random
Published on 2011-01-14T12:23:31Z
Indexed on
2011/01/16
11:53 UTC
Read the original article
Hit count: 163
A minimal example:
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent = None):
QtGui.QMainWindow.__init__(self, parent)
winWidth = 683
winHeight = 784
screen = QtGui.QDesktopWidget().availableGeometry()
screenCenterX = (screen.width() - winWidth) / 2
screenCenterY = (screen.height() - winHeight) / 2
self.setGeometry(screenCenterX, screenCenterY, winWidth, winHeight)
layout = QtGui.QVBoxLayout()
layout.addWidget(FormA())
mainWidget = QtGui.QWidget()
mainWidget.setLayout(layout)
self.setCentralWidget(mainWidget)
FormA
is a QFrame
with a VBoxLayout that can expand to an arbitrary number of entries.
In the code posted above, if the entries in the forms can't fit in the window then the window itself grows. I'd prefer for the window to become scrollable. I've also tried the following...
replacing
mainWidget = QtGui.QWidget()
mainWidget.setLayout(layout)
self.setCentralWidget(mainWidget)
with
mainWidget = QtGui.QScrollArea()
mainWidget.setLayout(layout)
self.setCentralWidget(mainWidget)
results in the forms and entries shrinking if they can't fit in the window.
Replacing it with
mainWidget = QtGui.QWidget()
mainWidget.setLayout(layout)
scrollWidget = QtGui.QScrollArea()
scrollWidget.setWidget(mainWidget)
self.setCentralWidget(scrollWidget)
results in the mainwidget (composed of the forms) being scrunched in the top left corner of the window, leaving large blank areas on the right and bottom of it, and still isn't scrollable.
I can't set a limit on the size of the window because I wish for it to be resizable.
How can I make this window scrollable?
© Stack Overflow or respective owner