I have a QGraphicsScene
and inside I have a few QGraphicsItem
s. When I hover over a QGraphicsRectItem
, I want to show an overlay text immediately. Only when the cursor leaves the item, then the text can disappear.
Below you can see I tried using whatsthis (which crashes python) and tooltip.
With tooltip, I am able to make the text appear immediately but the text disappears on its own after the built-in delay.
class Node(QGraphicsRectItem):
def __init__(self, x, y, w, h, qpen, qbrush, text):
QGraphicsRectItem.__init__(self)
self.setRect(x, y, w, h)
self.setBrush(qbrush)
self.setPen(qpen)
self.setAcceptHoverEvents(True)
self.text = text
#self.setFlag(QGraphicsItem.ItemIsMovable)
#self.toolkit = QToolTip()
#self.setToolTip(text)
#self.setWhatsThis(self.text)
def hoverEnterEvent(self, event):
QToolTip.showText(event.screenPos(),self.text)
#print("hoverEnterEvent : {}".format(event))
#print(type(self.toolTip))
#self.QToolTip.showText(event.pos(),text)
#event.ToolTip.showText(text)
#QWhatsThis.showText(event.screenPos(),self.text)
#self.enterWhatsThisMode()
def hoverLeaveEvent(self, event):
QToolTip.hideText()
#print("hoverLeaveEvent : {}".format(event))
#self.QToolTip.hideText()
#event.ToolTip.hideText()
#QWhatsThis.hideText()
#self.leaveWhatsThisMode()
I am using python 3.3 and pyside