I want to show a tooltip when dragging the endpoint of a line to a QGraphicsItem with the mouse pointer (no hovering).
So i have the mouse event and i want to call QToolTip::showText(QPoint pt, String str) and i want to show the tooltip at a normal position relative to the mouse pointer.
But whatever i try (widget.mapToGlobal, item.mapToScene) on event.pos() the tooltip appears realtive to the topleft of my screen or the graphicsview, not the mouse.
Maybe i am missing something simple, but i would really appreciate some help with this.
widget = item.scene().views()[0] #there is only one view
p = event.pos()
pt = widget.mapToGlobal(QtCore.QPoint(p.x(), p.y()))
QtGui.QToolTip.showText(pt, text)
QGraphicsSceneMouseEvent has another useful method - screenPos() which returns the mouse cursor position in scene coordinates. Try to use it. For example:
QtGui.QToolTip.showText(event.screenPos(), text)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With