[Qt-interest] High CPU usage with QGraphicsPathItem
Samuel Rødal
sroedal at trolltech.com
Fri Feb 27 09:42:07 CET 2009
Deepak Chandran wrote:
> I have noticed that the CPU usage goes high (rises from 0-3% to 30-50%)
> when I have a few (~ 2-3) QGraphicsPathItem objects drawn on the scene.
> The paths all contain beziers and their paths have been set using
> QPathStroker. This is not normal, is it?
>
> When debugging, I noticed that the path graphics items are constantly
> being redrawn, which would explain the issue. This is only happening for
> the path graphics items and not for other graphics items that I have
> drawn on the scene. The other graphics items are abstract shape items
> with beziers and other complex shapes as well, but they do not redraw
> themselves all the time. I tried overriding the boundingRect and
> sceneBoundingRect methods of QGraphicsPathItem so that they just return
> QRectF() just to check whether the bounding rect is the problem. I also
> did painter->setClipRect( option->exposedRect ) in the paint method. The
> problem did not go away.
>
> Any ideas?
>
> Thanks.
Try enabling caching for the items with
setCacheMode(QGraphicsItem::ItemCoordinateCache). If a pen is set on the
path items rendering them will be more expensive as a stroke needs to be
generated each time. You could also get around this by pre-generating
the stroke with QPainterPathStroker and instead setting the brush of the
items.
Regards,
Samuel
More information about the Qt-interest-old
mailing list