[Qt-qml] QML and graphics item caching

Adriano Rezende adriano.rezende at openbossa.org
Mon Sep 6 15:47:14 CEST 2010


Hi,

> You can use the QGraphicsEffect to achieve sub-tree caching...It's a bit "borderline"
> with an extra paint but it works.
>
> http://websvn.kde.org/trunk/playground/base/plasma/shells/mobile/shell/plasmaapp.cpp?revision=1169053&view=markup

This is really nice! It's a good way to add this support unofficially in QML.

I think the code just need a small fix... when the children are drawn
out of the parent's boundaries, some dirty regions are generated;
changing the composition mode to SourceOver seems to solve the problem
(it can be used?).

Some caution is needed to use this feature though; depending on the
children positioning (sparse elements) the source pixmap can get
really huge, leading to a high memory consumption.

An optimization can also be done in the QGraphicsEffect source code.
The problem is: If you set QGraphicsItem::ItemClipsChildrenToShape
flag in the parent (the root element of the graphics effect), the size
of the source pixmap generated in the effect is the union of all
children's bounding rect, regardless if this bounding rect is greater
than the parent's one. So, it will generate a big pixmap with
transparency all around, when all it's needed is a pixmap of the size
of the parent's bounding rect or less.
I believe a second optimization could also be done using pixmap tiles,
this would scale this solution for huge elements.

>> AFAIK cacheMode is not exposed in QML side. But for what you want
>> there is not official support even in QGraphicsView side.
>> There was an idea to implement a DeepItemCacheMode that would do
>> exactly this, but it was forgotten and never saw the daylight.
>
> Yes was too complex...

I thought it was not implemented because of the memory consumption
issue. Do you know what is the difference between this feature and the
cache feature already available in QGraphicsEffect?

Br,
Adriano



More information about the Qt-qml mailing list