[Qt-interest] How to put a QLayout in a QScrollArea ?

Stephen Collyer scollyer at netspinner.co.uk
Wed Dec 16 12:50:16 CET 2009


2009/12/15 Eric Clark <eclark at ara.com>

>  Stephen,
>
>
>
> A QScrollArea already, by default, has at least two widgets in it, the
> vertical scroll bar and the horizontal scroll bar. It is not an “empty”
> widget.
>

Yes, I realised this after the comment from Constantin.


> I would suggest that you read the layout overview, found here
> http://doc.trolltech.com/4.6/layout.html. This should help you understand
> layouts and widgets and their relationship to each other a little better.
>
>
I've read that many times. I don't think it really covers all the subtleties
of the interactions betweens widgets, layouts, sizeHints, sizePolicies, etc.


>  Like I said in my previous emails, simply making the layout a child of a
> widget, sets the widget’s layout to the layout that was made a child of it.
> If there is a layout already there, it gets overridden. So, this code:
>
>   QWidget* widget = new QWidget(this);
>   vbox_  = new QVBoxLayout(this);
>
>
>
> Overrides the layout for “this” which is the QScrollArea.
>

That's important to know if true (I didn't know it) but I can't find
anything in the Qt docs that confirms this. The docs for the QLayout ctor
says:

>QLayout::QLayout ( QWidget * parent )
>
>Constructs a new top-level QLayout, with parent parent. parent may not be
0.
>
>There can be only one top-level layout for a widget. It is returned by
>QWidget::layout().

which doesn't indicate that the layout for parent is set at this point. Do
you have a pointer to something in the docs that talks about this ?


>   QWidget* widget = new QWidget(this);
>   vbox_  = new QVBoxLayout(widget);
>
>  Obviously, it works the way you have it, but I am very surprised that it
> does.
>

Yes, it works fine, both with my original code and with your suggested mod.
But that indicates to me that your suggestion that "new QLayout(parent)"
sets the layout of parent is perhaps not correct.

-- 
Stephen Collyer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091216/01d5eba2/attachment.html 


More information about the Qt-interest-old mailing list