[Qt-interest] How do I get QScrollArea to let its widget expand?
Girish Ramakrishnan
girish at forwardbias.in
Fri Feb 25 05:29:13 CET 2011
Hi Kent,
Correct. Since you are using a layout for your widgetForScrolling, you
don't need to call setMinimumSize - the layout takes care of it.
Girish
On Fri, Feb 25, 2011 at 12:00 AM, kent williams
<nkwmailinglists at gmail.com> wrote:
> I actually was doing scrollArea->setWidget(widgetForScrolling); -- but
> I left it out of my code in the post.
>
> Actually what fixed it for me was to ignore the documentation for
> QScrollArea where it says
>
> "If a standard QWidget is used for the child widget, it may be
> necessary to call QWidget::setMinimumSize() to ensure that the
> contents of the widget are shown correctly within the scroll area."
>
> If I call setMinimumSize() the Widget for the widgetForScrolling, it
> stays the minimum size, and all the subwidgets get crammed in so you
> can't see them.
>
>
> On Thu, Feb 24, 2011 at 12:21 PM, Girish Ramakrishnan
> <girish at forwardbias.in> wrote:
>> 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