[Qt-interest] lazy evaluation of QListWidgetItem decorations?
Andre Somers
andre at familiesomers.nl
Fri Jun 11 09:55:01 CEST 2010
On 9-6-2010 18:29, Paul Miller wrote:
> I'm using a QListWidget and QListWidgetItems that override data() to
> return a custom DecorationRole. In this case, they are icons, and
> getting them can be expensive.
>
> I have several of these QListWidgets in a QTabWidget, and unfortunately
> the QListWidgets in hidden tabs are still calling data() to get the
> decoration. I only want this to happen on the QListWidgetItems that are
> ACTUALLY visible. It should wait until the user selects one of these
> hidden tabs to actually attempt to get the decoration.
>
> Is it possible to set this up to do this?
>
>
Problem is, that your decorations may have different sizes, and thus
impact the layout of the view. A QAbstractItemView-derived class is not
much more than a component to manage the layout of items, which are
rendered by a QAbstractItemDelegate-derived class. So, in order to know
these sizes, it needs to retreive the data on the images, unless...
1) you tell the QListView (QListWidget is derived from that class) that
all items have the same size using setUniformRowHeights. In that case it
will only query the height of the first item, and use that for all other
items; or
2) you not only reimplement data to return a decoration, but also a size
hint. If a size hint is supplied by the model (or the QListWidgetItem,
which will supply it to the model in turn), then that size hint will be
used for the layout calculations.
Alternatively, you could choose not to actually populate the lists
before showing them. At least that will save them from being layed out
needlessly.
HTH,
André
--
Nokia Certified Qt Developer.
Interested in Qt related job offers or freelance Qt consulting work.
More information about the Qt-interest-old
mailing list