[Qt-interest] [Fwd: Re: Display list of arbitrary widgets ?]
Stephen Collyer
scollyer at netspinner.co.uk
Fri Dec 18 15:21:09 CET 2009
2009/12/11 Stephen Collyer <scollyer at netspinner.co.uk>
> 2009/12/10 Sean Harmer <sean.harmer at maps-technology.com>
>
>
>> QListWidget::setItemWidget( QListWidgetItem*, QWidget* )
>>
>> http://doc.trolltech.com/4.6/qlistwidget.html#setItemWidget
>>
>
> Thanks. I seem to have overlooked that. However, I note that it says that
> it is restricted to the display of "static" content; what counts as static
> content in this context ? My custom widget will contain a QLCDNumber,
> displaying a time ticking away, so in some sense it won't be "static".
>
To reprise this topic:
It seems perfectly possible to display custom widgets in a QListWidget using
QListWidget::setItemWidget; however, in addition, to have the widgets
rendered correctly, you must also set the sizeHint for the QListWidgetItem
(since otherwise, I guess, the QListWidget layout manager doesn't know how
much space to allocate for the custom widget). So I have code like so:
QuestionSelectorList::QuestionSelectorList(const QList<QuestionSelector *>
qsels,
QWidget* parent)
: QListWidget(parent)
{
foreach (QuestionSelector* qsel, qsels)
{
QListWidgetItem* item = new QListWidgetItem(this);
item->setSizeHint(qsel->sizeHint());
addItem(item);
setItemWidget(item, qsel);
}
}
which does the job. In addition, my custom widgets are rerendered correctly
when their content changes (I have a timer updating a QLCDNumber), so the
limitation to "static" content mentioned in the docs for
QListWidget::setItemWidget doesn't mean that their rendering must be static;
I guess it means that they can't change their layout after having been added
to the QListWidget.
--
Stephen Collyer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091218/b6399e85/attachment.html
More information about the Qt-interest-old
mailing list