[Qt-interest] QScrollArea::resize() does not resize the viewport
John McClurkin
jwm at nei.nih.gov
Mon May 3 14:22:33 CEST 2010
Nikos Chantziaras wrote:
> Calling resize() or setGeometry() on a QScrollArea results in the
> viewport() dimensions not being updated:
>
> void foo( QScrollArea* scr )
> {
> scr->resize(500, 500);
> do_some_stuff(scr->viewport()->size());
> }
>
> do_some_stuff() receives a wrong size. Is this normal? For the code to
> work correctly, I need to do:
>
>
> void foo( QScrollArea* scr )
> {
> scr->viewport()->resize(500, 500); // <-- Smells funny
> do_some_stuff(scr->viewport()->size());
> }
>
> Why is that? When the QScrollArea is resized with the mouse, the
> viewport changes accordingly. When it's resized by code (like above),
> the viewport doesn't change.
After setting the object size with resize from code, you need to let the
event loop run to actually do the resize. You can try putting
QApplication::processEvents() after scr->resize. Alternately, send a
signal after scr->resize and calling do_some_stuff in a slot connected
to that signal.
More information about the Qt-interest-old
mailing list