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.
Press Alt + Spacebar to open the window's menu. If the window is maximized, arrow down to Restore and press Enter . Press Alt + Spacebar again to open the window menu, arrow down to Size, and press Enter .
Once you have add your layout with at least one widget in it, select your window and click the "Update" button of QtDesigner. The interface will be resized at the most optimized size and your layout will fit the whole window. Then when resizing the window, the layout will be resized in the same way.
Move or resize a window using only the keyboard. Press Alt + F7 to move a window or Alt + F8 to resize. Use the arrow keys to move or resize, then press Enter to finish, or press Esc to return to the original position and size. Maximize a window by dragging it to the top of the screen.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With