Quantcast
Channel: User spraff - Stack Overflow
Viewing all articles
Browse latest Browse all 66

QGraphicsScene.items() only returning items whose pos() exactly matches a test point, not items which contain the test point

$
0
0

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_modebehaviour
Qt.ContainsItemShapeitems is empty
Qt.IntersectsItemShapeitems contains an item if item.pos()==scene_pos
Qt.ContainsItemBoundingRectitems is empty
Qt.IntersectsItemBoundingRectitems 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?


Viewing all articles
Browse latest Browse all 66

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>