[Qt-interest] How to put a QLayout in a QScrollArea ?
Constantin Makshin
cmakshin at gmail.com
Tue Dec 15 15:49:24 CET 2009
There's no magic. QScrollArea needs and uses its own layout for scroll
bar[s]. Also documentation clearly describes QScrollArea'ss purpose and
the way its contents must be specified: "A scroll area is used to display
the contents of a child widget within a frame. ... The child widget must
be specified with setWidget()."
On Tue, 15 Dec 2009 17:02:40 +0300, Stephen Collyer
<scollyer at netspinner.co.uk> wrote:
> 2009/12/14 Eric Clark <eclark at ara.com>
>> 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 ?
--
Constantin Makshin
More information about the Qt-interest-old
mailing list