James James - 1 year ago 169
C++ Question

Should QGraphicsItem::boundingRect() include child bounding rects?

Googling suggests that it should.

But the dragdroprobot example implementation (on the parent Robot object) suggests not:

QRectF Robot::boundingRect() const
return QRectF();

Which is correct, or is there something more subtle going on?

Answer Source

Child items are painted directly by the scene not by the parent, and according to the documentation about boundingRect():

QGraphicsView uses this to determine whether the item requires redrawing.

So, if there is no drawing to do in the parent, there is no need to return a non-null bounding rectangle, even if the parent has child items. And if there is some drawing in the parent, it only needs to contain its own bounding rectangle.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download