18
18
from napari .utils .events import Event
19
19
from napari .utils .history import get_save_history , update_save_history
20
20
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
22
22
from qtpy .QtWidgets import (
23
23
QButtonGroup ,
24
24
QCheckBox ,
@@ -989,6 +989,26 @@ def dropEvent(self, event):
989
989
self .sig_dropped .emit (event )
990
990
991
991
992
+ class ClickableLabel (QLabel ):
993
+ clicked = Signal (str )
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 (self .text ())
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
+
992
1012
class LabelPair (QWidget ):
993
1013
def __init__ (self , color : str , name : str , parent : QWidget ):
994
1014
super ().__init__ (parent )
@@ -997,7 +1017,7 @@ def __init__(self, color: str, name: str, parent: QWidget):
997
1017
self ._part_name = name
998
1018
999
1019
self .color_label = QLabel ("" , parent = self )
1000
- self .part_label = QLabel (name , parent = self )
1020
+ self .part_label = ClickableLabel (name , color = color , parent = self )
1001
1021
1002
1022
self .color_label .setToolTip (name )
1003
1023
self .part_label .setToolTip (name )
@@ -1057,6 +1077,15 @@ def __init__(self, parent):
1057
1077
1058
1078
self ._build ()
1059
1079
1080
+ @property
1081
+ def labels (self ):
1082
+ labels = []
1083
+ for i in range (self ._layout .count ()):
1084
+ item = self ._layout .itemAt (i )
1085
+ if w := item .widget ():
1086
+ labels .append (w )
1087
+ return labels
1088
+
1060
1089
def _build (self ):
1061
1090
self ._container .setSizePolicy (
1062
1091
QSizePolicy .Fixed , QSizePolicy .Maximum
0 commit comments