Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight instance box on hover #2055

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

Comment on lines +1613 to +1616
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove debug print and enhance hover feedback

The hover implementation for QtNode needs improvement:

  1. Debug print statement should be removed from production code
  2. Missing corresponding hoverLeaveEvent implementation
  3. No visual feedback on hover

Consider this implementation:

def hoverEnterEvent(self, event):
-    print("QtNode: hover enter")
+    self.setBrush(self.brush.color().lighter())
+    self.setCursor(Qt.PointingHandCursor)
     return super().hoverEnterEvent(event)

+def hoverLeaveEvent(self, event):
+    self.setBrush(self.brush)
+    self.unsetCursor()
+    return super().hoverLeaveEvent(event)

Committable suggestion skipped: line range outside the PR's diff.


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
Loading