A QGraphicsScene contains a number of MyItem items.
A MyItem is a QGraphicsItemGroup which contains, among other child items, a QGraphicsEllipseItem centred at the local origin.
A number of MyItem items render correctly at various positions in the scene.
Where scene_pos is a QPointF, I try
items = scene.items(scene_pos, selection_mode)
and I want to get every MyItem whose boundingRect() contains scene_pos
These are the behaviours I observe:
selection_mode | behaviour |
---|---|
Qt.ContainsItemShape | items is empty |
Qt.IntersectsItemShape | items contains an item if item.pos()==scene_pos |
Qt.ContainsItemBoundingRect | items is empty |
Qt.IntersectsItemBoundingRect | items contains an item if item.pos()==scene_pos |
I also tried replacing scene_pos with a small QRectF around this pos -- same behaviour.
If I'm reading the documentation for ItemSelectionMode correctly, I want IntersectsItemBoundingRect
The output list contains both items whose bounding rectangle is fully contained inside the selection area, and items that intersect with the area's outline. This method is commonly used for determining areas that need redrawing.
If an ellipse with radius, say 100, has local origin (0,0) and its parent item pos() is, say, (1000,1000) and scene_pos is (1001,1001) (or using something like QRectF(999,999,2,2)) then scene_pos is clearly within the ellipse, and hence intersects it, right? In this example it would only work if scene_pos is (1000,1000).
Why isn't this working as expected?