Reputation: 2444
I'm very experienced with Qt's QGraphicsScene
, but I'm hoping someone can clarify a detail with regard to the boundingRect
and shape
methods for a QGraphicsItem
. As far as I can find, the documentation doesn't address this specific concern.
I have a situation where I need to calculate a shape for many complex paths with the shape including a slight buffer zone to make the paths easier for the user to click on and select. I'm using the QPainterPathStroker
, and it's expensive. I'm currently attempting to delay the shape calculation until the shape method is actually called, and that's helping with the performance.
The situation now is that the bounding rectangle is calculated from the path boundaries plus any pen width, which is correct for enclosing the painted area. However, when the shape
result is calculated, it is larger than the bounding rectangle because the selection buffer zone is larger than the drawing area.
Is that a problem? Is it acceptable that the boundingRect
does NOT enclose the shape
result area? Or do I need to recalculate the boundingRect
when I recalculate the shape
?
Thank you.
Doug McGrath
Upvotes: 2
Views: 765
Reputation: 27611
QGraphicsItem::shape is used for object collision detection, hit tests and knowing where mouse clicks occur.
In contrast, QGraphicsItem::boundingRect is used when drawing an object, knowing when an object is off the screen, or obscured. As the documentation states for boundingRect: -
QGraphicsView uses this to determine whether the item requires redrawing.
Therefore, the boundingRect should wholly encompass the QPainterPath
returned from the shape function.
Upvotes: 2