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

Stephen Collyer scollyer at netspinner.co.uk
Tue Dec 15 15:02:40 CET 2009


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

>  When you set the layout of the scroll area to be the VBoxLayout, you
> override the layout that controls the scroll bars in the QScrollArea. Do you
> not get a warning in your command console that says your
> QuestionSelectorList already has a layout?
>
>
No, I get nothing.

> QWidget’s do not have layouts by default, but some subclasses, like
> QScrollArea, I believe, already does
>

That sounds odd. Why should an empty QScrollArea have a layout ?

Anyway, I've modified my original code based on your suggestion thus:

QuestionSelectorList::QuestionSelectorList(const QList<QuestionSelector *>
qsels,
                                           QWidget* parent)
                       : QScrollArea(parent)
{
    QWidget* widget = new QWidget(this);
    vbox_  = new QVBoxLayout(this);

    foreach (QuestionSelector* qsel, qsels)
    {
        vbox_->addWidget(qsel);
    }

    widget->setLayout(vbox_);
    setWidget(widget);
}

and this works fine. Thanks.

Would it be sacreligious of me to suggest that the Qt layout system is full
of black magic and hidden secrets ?

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


More information about the Qt-interest-old mailing list