[Qt-interest] QGraphicsRectItem::boundingRect() bug/fix?

Malyushytsky, Alex alex at wai.com
Wed Jan 27 03:31:21 CET 2010


I've got a problem in QT 4.6, which seems as a bug to me.

For some reason QGraphicsRectItem::boundingRect() assumes that d->rect  is normalized,
which is not correct when width / heights are negative.
This makes such items not being properly updated (in most cases not updated at all, unless you force scene to update that area in other way.

In my case I was able to fix the problem by overriding QGraphicsRectItem::boundingRect() as in below:

QRectF UbGraphicsRectItem::boundingRect() const
{
         return QGraphicsRectItem::boundingRect().normalized();
}

But this breaks the QGraphicsRectItem cashing of bounding rectangle, which makes the code slower and might be incorrect if pen width is set.

The right thing probably would be to fix  QGraphicsRectItem::boundingRect() as below:

QRectF QGraphicsRectItem::boundingRect() const
{
    Q_D(const QGraphicsRectItem);
    if (d->boundingRect.isNull()) {
        qreal halfpw = pen().widthF() / 2;
//        d->boundingRect = d->rect; // to replace
        d->boundingRect = d->rect.normalized(); // fix
        if (halfpw > 0.0)
            d->boundingRect.adjust(-halfpw, -halfpw, halfpw, halfpw);
    }
    return d->boundingRect;
}

I would report the bug, but not sure this was not intended.
Anybody could comment on this?


Alex Malyushytsky
Research Engineer - Weidlinger Associates Inc.
office: 650 230 0210,
direct: 650 230 0349
web: http://www.wai.com


---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.

"This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you."

"Please consider our environment before printing this email."




More information about the Qt-interest-old mailing list