How do I make QScrollArea consume available vertical space inside a QVBoxLayout?



  • I have a QScrollArea wrapping a custom widget (with children laid out by a QVBoxLayout), and the QScrollArea is itself laid out by a QVBoxLayout. The wrapped widget is large enough to make a vertical scroll bar appear. Basically the (Python) code is like this:

    @
    layout = QtWidgets.QVBoxLayout(parent_widget)
    [...]
    form_scroll = QtWidgets.QScrollArea()

    form_widget is a custom widget with children laid out by QVBoxLayout

    form_scroll.setWidget(form_widget)
    form_scroll.setWidgetResizable(True)
    layout.addWidget(form_scroll, 1)
    @

    My problem is that the QScrollArea doesn't expand to consume available space in the vertical direction (horizontally it's fine). How do I make it expand vertically?



  • I found the reason, which wasn't evident before the QScrollArea was introduced: I had called addStretch(1) on the layout object, which compressed the laid out widgets (including the QScrollArea).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.