Solved QGraphicsItemGroup tooltip shown in the wrong place
-
I use
PySide2
v5.14.1 on Debian. There's a class that inherits fromQGraphicsItemGroup
to create and manage multipleQGraphicsEllipseItem
as if they're one logical entity. I set a tooltip for the group and it works as expected.However, if I move my group to some other place on the
QGraphicsScene
, hovering the mouse over the object does not produce a tooltip. At the same time, I noticed that if I move the mouse to the old location of my object - the tooltip is shown, as if my object is still there at the old coordinates.- How can one ensure that the tooltip moves along with the object?
- Is it possible in principle?
Any suggestions on how to troubleshoot this would be greatly appreciated.
-
Show your subclass.
I bet, you forgot to pass the new position to its base class, so that from scene's point of view, the item is still at its old position, which triggers the tooltip there. -
Thank you for your reply - you are right, the position of the group was indeed not updated.
For the benefit of future archaeologists digging in this area, here are some additional clues:
- the
update
method of my subclass was changing the position of the group's individual elements, - but not the position of the group itself
- thus, everything was visually in the correct location
- but logically the group was still in its old place
Therefore, one needs to ensure that the
update
method callsself.setPos(...)
somewhere. - the
-
@ralienpp said in QGraphicsItemGroup tooltip shown in the wrong place:
thus, everything was visually in the correct location
but logically the group was still in its old placeYes, exactly :)
one needs to ensure that the update method calls self.setPos(...) somewhere
This should happen automatically, if your subclass is correct (every change passed to base class). Usually there's no need to call
update()
to make position changes.
If you move your custom item by e.g. mouse dragging the moveEvent is propagated to the base classQGraphicsItem
or-Group
which holds the position. Your position change was probably made only in your subclass, which paints your item at that position, but won't move it.