Qt, differences between event.pos(), event.scenePos(), self.scenePos()
-
As far as I know, event.pos(), event.scenePos() seem exchangeable.
self.scenePos() is like the topleft point of the boundingRect of current graphics.But I am not quite sure. Thanks in advance for your comments.
-
It would be nice to say what
self
andevent
are. I'm guessing aQGraphicsItem
and a parameter ofQGraphicsSceneMouseEvent
? Is that right?If so then
event.pos()
andevent.scenePos()
are not exchangeable. The first one is cursor position in item's coordinates and the second one cursor position in scene coordinates. They are the same only when item is placed at (0,0). If item is moved they will differ. It's important to note that these values are what they were at the time the event took place, which might be different from the "current" values for item (this is a good thing). For example if you move your mouse fast and there are a lot of events generated the cursor position in these events will be a little behind the actual current position of the cursor before they "catch up".As for
self.scenePos()
- this is the position of the item in the scene. This is the point relative to which theevent.pos()
is calculated. It is not necessary the top left of the bounding rect. It can be placed anywhere using 'setTransformOriginPoint()'. It is often set to the center of the item. For example if you have a bunch of draggable circles a center is probably more convenient than a top left corner. For vertical bars on a chart the origin might be placed at the middle bottom of a bar etc.