Making a QScrollArea take only the space it's contents need
-
I have a QDialog in Qt Creator with a horizontal layout that contains two vertical layout columns.
In the left column, I have a QGridBox that gets populated. I'm trying to get the left column to expand only as much as needed to fit the contents in the grid, and allocate the remaining space to the right column.
The issue I am running into is that I end up with a horizontal scrollbar on the left column. Setting both size policies to expanding means each column gets an equal amount of the available space, which can result in the left column being too small for it's contents.
With the right column set to preferred, I end up with a gap of space in the middle, as the left column expands to the available space beyond what it needs for the grid items.
How can I make the right column take up the remaining available space, without it taking from the left one? If I insert some example items into the Grid Layout in Qt Creator, I can see that the grid and parent scroll contents widget have their geometry size to fit those items, but the container QScrollArea does not.
-
I fiddled with QScrollArea too recently.
My advice: try to solve column layout without QScrollArea. Check
QWidget::minimumSizeHint
.
When your column layout works without QScrollArea, then adding QScrollArea withsetWidgetResizable(true)
should do the job. At least it worked for me.