diff --git a/src/napari_deeplabcut/_widgets.py b/src/napari_deeplabcut/_widgets.py index 8111067..cf3ded9 100644 --- a/src/napari_deeplabcut/_widgets.py +++ b/src/napari_deeplabcut/_widgets.py @@ -18,7 +18,7 @@ from napari.utils.events import Event from napari.utils.history import get_save_history, update_save_history from qtpy.QtCore import Qt, QTimer, Signal, QSize, QPoint, QSettings -from qtpy.QtGui import QPainter, QIcon, QAction +from qtpy.QtGui import QPainter, QIcon, QAction, QCursor from qtpy.QtWidgets import ( QButtonGroup, QCheckBox, @@ -989,6 +989,26 @@ def dropEvent(self, event): self.sig_dropped.emit(event) +class ClickableLabel(QLabel): + clicked = Signal(str) + + def __init__(self, text="", color="turquoise", parent=None): + super().__init__(text, parent) + self._default_style = self.styleSheet() + self.color = color + + def mousePressEvent(self, event): + self.clicked.emit(self.text()) + + def enterEvent(self, event): + self.setCursor(QCursor(Qt.PointingHandCursor)) + self.setStyleSheet(f"color: {self.color}") + + def leaveEvent(self, event): + self.unsetCursor() + self.setStyleSheet(self._default_style) + + class LabelPair(QWidget): def __init__(self, color: str, name: str, parent: QWidget): super().__init__(parent) @@ -997,7 +1017,7 @@ def __init__(self, color: str, name: str, parent: QWidget): self._part_name = name self.color_label = QLabel("", parent=self) - self.part_label = QLabel(name, parent=self) + self.part_label = ClickableLabel(name, color=color, parent=self) self.color_label.setToolTip(name) self.part_label.setToolTip(name) @@ -1057,6 +1077,15 @@ def __init__(self, parent): self._build() + @property + def labels(self): + labels = [] + for i in range(self._layout.count()): + item = self._layout.itemAt(i) + if w := item.widget(): + labels.append(w) + return labels + def _build(self): self._container.setSizePolicy( QSizePolicy.Fixed, QSizePolicy.Maximum