[Qt-interest] How do I get QScrollArea to let its widget expand?

Girish Ramakrishnan girish at forwardbias.in
Thu Feb 24 19:21:03 CET 2011


Hi,

On Thu, Feb 24, 2011 at 9:23 PM, kent williams
<nkwmailinglists at gmail.com> wrote:
> Every time I have to do this, I have to try a bunch of different
> permutations to get it to work, and THEN what I end up doing doesn't
> WORK in the next context in which I try to do the SAME THING, so now
> I'm asking how do I get this to work properly?
>
> QScrollArea *scrollArea = new QScrollArea(parent);
>
> QWidget *widgetForScrolling = new QWidget(scrollArea);
>

This only makes widgetForScrolling a child of the scrollArea. A
QScrollArea does not show scrollbars based on it's children's
geometry, but based on the widget you set using
QScrollArea::setWidget(). So, what's missing is:

scrollArea->setWidget(widgetForScrolling);

The above call actually reparent the widgetForScrolling into
QScrollArea's internal viewport widget. So, passing the parent
argument can mislead you into thinking scrollArea is the parent of
widgetForScrolling.

Girish



More information about the Qt-interest-old mailing list