Skip to content

Commit

Permalink
Highlight instance box on hover
Browse files Browse the repository at this point in the history
  • Loading branch information
talmo committed Dec 16, 2024
1 parent 1717025 commit 26feff1
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion sleap/gui/widgets/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -1610,6 +1610,10 @@ def mouseDoubleClickEvent(self, event: QMouseEvent):
view = scene.views()[0]
view.instanceDoubleClicked.emit(self.parentObject().instance, event)

def hoverEnterEvent(self, event):
print("QtNode: hover enter")
return super().hoverEnterEvent(event)


class QtEdge(QGraphicsPolygonItem):
"""
Expand Down Expand Up @@ -1809,6 +1813,7 @@ def __init__(
self.labels = {}
self.labels_shown = True
self._selected = False
self._is_hovering = False
self._bounding_rect = QRectF()

# Show predicted instances behind non-predicted ones
Expand All @@ -1830,6 +1835,7 @@ def __init__(
box_pen.setStyle(Qt.DashLine)
box_pen.setCosmetic(True)
self.box.setPen(box_pen)
self.setAcceptHoverEvents(True)

# Add label for highlighted instance
self.highlight_label = QtTextWithBackground(parent=self)
Expand Down Expand Up @@ -1991,7 +1997,12 @@ def updateBox(self, *args, **kwargs):
select this instance.
"""
# Only show box if instance is selected
op = 0.7 if self._selected else 0
op = 0
if self._selected:
op = 0.8
elif self._is_hovering:
op = 0.4

self.box.setOpacity(op)
# Update the position for the box
rect = self.getPointsBoundingRect()
Expand Down Expand Up @@ -2085,6 +2096,16 @@ def paint(self, painter, option, widget=None):
"""Method required by Qt."""
pass

def hoverEnterEvent(self, event):
self._is_hovering = True
self.updateBox()
return super().hoverEnterEvent(event)

def hoverLeaveEvent(self, event):
self._is_hovering = False
self.updateBox()
return super().hoverLeaveEvent(event)


class VisibleBoundingBox(QtWidgets.QGraphicsRectItem):
"""QGraphicsRectItem for user instance bounding boxes.
Expand Down

0 comments on commit 26feff1

Please sign in to comment.