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

Stephen Collyer scollyer at netspinner.co.uk
Mon Dec 14 20:25:20 CET 2009


2009/12/14 Sean Harmer <sean.harmer at maps-technology.com>

>
> QVBoxLayout* layout = new QVBoxLayout;
> // Add widgets to layout...
>
> QWidget* w = new QWidget;
> w->setLayout( layout );
>
> myScrollArea->setWidget( w );
>

Well, I've tried a variant of this:

 class QuestionSelectorList : public QScrollArea
{
    Q_OBJECT

    public:
        QuestionSelectorList(const QList<QuestionSelector *> qsels,
                             QWidget* parent = 0);
        ~QuestionSelectorList();

    private:
        QVBoxLayout* vbox_;
};

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

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

    setLayout(vbox_);
}

and this doesn't work properly. It fails to show any QuestionSelector
widgets initially but if resized, it reveals more and more of them. It's as
if the QScrollArea is failing to get a meaningful size for vbox_ for some
reason. (It never displays a scroll bar either).

Any ideas ?

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


More information about the Qt-interest-old mailing list