Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
4.7.2, 5.1.0
-
None
-
5ec344cc7796b8708e2ae722f7cd184c56844504
Description
When calling QGrahpicsScene::items() with IntersectsItemBoundingRect, items with custom shapes are not selected if the point is outside of the shape. Consider the following code:
class ZeroShapeItem : public QGraphicsRectItem { public: ZeroShapeItem(QRectF r) : QGraphicsRectItem(r) {} QPainterPath shape() const { return QPainterPath(); } }; main() { QGraphicsScene scene; scene.addItem(new ZeroShapeItem(QRectF(0, 0, 100, 100))); QList<QGraphicsItem*> items = scene.items(QPointF(10, 10), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder); }
The returned items will be empty since the scene still calls contains() after testing for bounding rects intersection (at around line 160 in qgraphicssceneindex.cpp). By default. contains() test for shape intersection. Since the item has an empty shape, it's excluded.
From the wording of the doucmentation, IntersectsItemBoundingRect should return items whose bounds intersects the requested point regardless of its shape.