Skip to content

Commit 2b03ca5

Browse files
committed
Replace QLabels in ColorSchemeDisplay with ClickableLabels
1 parent 66da173 commit 2b03ca5

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/napari_deeplabcut/_widgets.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from napari.utils.events import Event
1919
from napari.utils.history import get_save_history, update_save_history
2020
from qtpy.QtCore import Qt, QTimer, Signal, QSize, QPoint, QSettings
21-
from qtpy.QtGui import QPainter, QIcon, QAction
21+
from qtpy.QtGui import QPainter, QIcon, QAction, QCursor
2222
from qtpy.QtWidgets import (
2323
QButtonGroup,
2424
QCheckBox,
@@ -989,6 +989,26 @@ def dropEvent(self, event):
989989
self.sig_dropped.emit(event)
990990

991991

992+
class ClickableLabel(QLabel):
993+
clicked = Signal()
994+
995+
def __init__(self, text="", color="turquoise", parent=None):
996+
super().__init__(text, parent)
997+
self._default_style = self.styleSheet()
998+
self.color = color
999+
1000+
def mousePressEvent(self, event):
1001+
self.clicked.emit()
1002+
1003+
def enterEvent(self, event):
1004+
self.setCursor(QCursor(Qt.PointingHandCursor))
1005+
self.setStyleSheet(f"color: {self.color}")
1006+
1007+
def leaveEvent(self, event):
1008+
self.unsetCursor()
1009+
self.setStyleSheet(self._default_style)
1010+
1011+
9921012
class LabelPair(QWidget):
9931013
def __init__(self, color: str, name: str, parent: QWidget):
9941014
super().__init__(parent)
@@ -997,7 +1017,7 @@ def __init__(self, color: str, name: str, parent: QWidget):
9971017
self._part_name = name
9981018

9991019
self.color_label = QLabel("", parent=self)
1000-
self.part_label = QLabel(name, parent=self)
1020+
self.part_label = ClickableLabel(name, parent=self)
10011021

10021022
self.color_label.setToolTip(name)
10031023
self.part_label.setToolTip(name)

0 commit comments

Comments
 (0)