[Qt-interest] Item selection in QGraphicsScene and QGraphicsView with QPoint/QPointF
Stephen Chu
stephen at ju-ju.com
Sat Apr 2 20:17:53 CEST 2011
I've been trying to track down an graphics item cursor and selection
problem in my app. My app treats 1 unit in a scene as 1 inch and
depending on the resolution of the image file, it can be around 1000 to
2540 dpi or more. The floating point coordinate system in QGraphicsScene
and item's local transformation work really well in this application
since all the difference of pixel resolutions is handled inside of the
item itself. Everything outside of the item just work on absolute
lengths. Perfect.
But then I run into this bug:
<http://bugreports.qt.nokia.com/browse/QTBUG-17985> Basically Qt is
using a 1x1 rect for intersection test to see if a item is under the
cursor. Problem is, that 1x1 square is 1-inch square in my code which
means it can be off by as much as 1000s of pixels.
The fix proposed in the bug works for my selection issue. So I created a
MR for it. Then I did more investigate on the issue. I find although
QGraphicsSceneIndex does provide a items() call that returns items under
the scene point using QGraphicsSceneIndexPointIntersector, almost all
QGraphicsView and QGraphicsScene functions use the rect or even polygon
version to do the point test. This exposes them to the bug when a scene
unit is mapped to more than several view pixels.
Even QGraphicsSceneIndexPointIntersector::intersect() builds a 1x1 scene
rect and test intersection with it before calling
QGraphicsItem::contains() for the actual test.
This is a serious issue and I can see a lot of issues caused from it.
The problem is the behavior is really widespread in the graphics view
code. The only workaround I have now is the multiply my scene unit by
1000 or even 10000, ie, 10000 units in scene is 1 inch.
I don't really know the inner working of QGrahpicsScene so I am not sure
how this can be fixed or is it even intended. Can some Troll shed some
light on this? Thanks.
Stephen Chu
More information about the Qt-interest-old
mailing list