Reputation: 4500
I have a window containing a QScrollArea
with a couple widgets in it.
Until now, I was creating the QScrollArea
and its child widgets in the constructor of my window, and then I was resizing the window vertically to fit its content using resize(400, sizeHint().height())
. So far, so good.
Now, I'm adding or removing widgets in the QScrollArea
at runtime. What should I do, after having added or removed widgets, to make the window fits its content vertically? Should I call adjustSize()
? resize(sizeHint())
? Should there be a call to layout->activate()
or maybe updateGeometry()
first? Which size policies actually matter in this case? The ones of the window, or of the scroll area, or both? I tried to set them all to Expanding
.
I'm using Qt 4.6 on Windows.
Upvotes: 12
Views: 19619
Reputation: 4500
It seems that calling resize(sizeHint())
(without any other magic) after widgets were added to the scroll area actually does the trick. Somehow missed that the first time.
Upvotes: 12