Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to position a tooltip in qt graphicsview

Tags:

qt

pyside

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) 
like image 610
Lars Avatar asked Oct 21 '25 15:10

Lars


1 Answers

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) 
like image 183
Kosovan Avatar answered Oct 23 '25 06:10

Kosovan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!