Skip to content

Commit 93de4d1

Browse files
committed
[processing] Show tooltips in modeler when hovering over model component
1 parent b5146db commit 93de4d1

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

python/plugins/processing/modeler/ModelerGraphicItem.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class ModelerGraphicItem(QGraphicsItem):
5151

5252
def __init__(self, element, model, controls, scene=None):
5353
super(ModelerGraphicItem, self).__init__(None)
54+
self.setAcceptHoverEvents(True)
5455
self.controls = controls
5556
self.model = model
5657
self.scene = scene
@@ -175,6 +176,18 @@ def boundingRect(self):
175176
def mouseDoubleClickEvent(self, event):
176177
self.editElement()
177178

179+
def hoverEnterEvent(self, event):
180+
self.updateToolTip(event)
181+
182+
def hoverMoveEvent(self, event):
183+
self.updateToolTip(event)
184+
185+
def updateToolTip(self, event):
186+
if self.itemRect().contains(event.pos()):
187+
self.setToolTip(self.text)
188+
else:
189+
self.setToolTip('')
190+
178191
def contextMenuEvent(self, event):
179192
if isinstance(self.element, QgsProcessingModelOutput):
180193
return
@@ -291,12 +304,15 @@ def getAdjustedText(self, text):
291304
w = fm.width(text)
292305
return text
293306

294-
def paint(self, painter, option, widget=None):
295-
rect = QRectF(-(ModelerGraphicItem.BOX_WIDTH + 2) / 2.0,
307+
def itemRect(self):
308+
return QRectF(-(ModelerGraphicItem.BOX_WIDTH + 2) / 2.0,
296309
-(ModelerGraphicItem.BOX_HEIGHT + 2) / 2.0,
297310
ModelerGraphicItem.BOX_WIDTH + 2,
298311
ModelerGraphicItem.BOX_HEIGHT + 2)
299312

313+
def paint(self, painter, option, widget=None):
314+
rect = self.itemRect()
315+
300316
if isinstance(self.element, QgsProcessingModelParameter):
301317
color = QColor(238, 242, 131)
302318
stroke = QColor(234, 226, 118)

0 commit comments

Comments
 (0)