1
votes

I have a dialog with a programmatically generated menu consisting of flat QPushButtons in a QVBoxLayout. I want it to size to fit the buttons horizontally, and be scrollable vertically. I put this inside a QScrollArea and disabled the horizontal scrollbar. I want the scroll area width to match the menu width so that all of the buttons are fully shown width-wise, even if that means shrinking the buttons, but preferably keep the scroll area width big enough to contain the buttons' minimum size.

I am not getting the behaviour I want.

If I specify false for the QScrollArea's widgetResizable property then the scroll area is empty. Even if I enable horizontal scrolling, there are no scrollbars. My guess is that, even after adding buttons and calling updateLayout() on them, the menu widget has zero size.

If I specify true for the QScrollArea's widgetResizable property then the scroll child (the menu) is resized to be wider than it needs to be and wider than fits in the QScrollArea. My buttons are truncated.

1

1 Answers

1
votes

Override QScrollArea.resizeEvent and adjust QScrollArea.widget()'s width in it.