PDA

View Full Version : Why doesn't QT cache the bounding rect for QPainterPaths?



mooreaa
1st July 2008, 08:44
I had a HUGE performance issue and wasn't sure what was causing it, I eventually narrowed it down to a QPainterPath boundingRect() issue.

I had a QGraphicsItem subclasses line which drew its line with a QPainterPath. So in the subclassed class's boundingRect() function I called mypath.boundingRect(). Turns out that thats a really slow call!.

Saving the results to a QRectF had a drastic impact on performance.

Why doesn't it internally cache the bounding rect if its computation is complex?

jacek
2nd July 2008, 03:55
It seems that Qt 4.4.0 does cache it:

QRectF QPainterPath::boundingRect() const
{
if (!d_ptr)
return QRectF();
QPainterPathData *d = d_func();

if (d->dirtyBounds)
computeBoundingRect();
return d->bounds;
}
Which Qt version do you use?

mooreaa
3rd July 2008, 04:24
Hmm then I must be doing something that is causing it to think it needs to recaculate all the time. :(

Is there a good way to identify this kind of a bug?

jacek
12th July 2008, 23:51
Hmm then I must be doing something that is causing it to think it needs to recaculate all the time.
Maybe you create a new path every time?