22
22
from napari .utils .events import Event
23
23
from napari .utils .history import get_save_history , update_save_history
24
24
from qtpy .QtCore import Qt , QTimer , Signal , QSize , QPoint , QSettings
25
- from qtpy .QtGui import QPainter , QIcon , QAction
25
+ from qtpy .QtGui import QPainter , QIcon , QAction , QCursor
26
26
from qtpy .QtWidgets import (
27
27
QButtonGroup ,
28
28
QCheckBox ,
@@ -1110,6 +1110,26 @@ def dropEvent(self, event):
1110
1110
self .sig_dropped .emit (event )
1111
1111
1112
1112
1113
+ class ClickableLabel (QLabel ):
1114
+ clicked = Signal (str )
1115
+
1116
+ def __init__ (self , text = "" , color = "turquoise" , parent = None ):
1117
+ super ().__init__ (text , parent )
1118
+ self ._default_style = self .styleSheet ()
1119
+ self .color = color
1120
+
1121
+ def mousePressEvent (self , event ):
1122
+ self .clicked .emit (self .text ())
1123
+
1124
+ def enterEvent (self , event ):
1125
+ self .setCursor (QCursor (Qt .PointingHandCursor ))
1126
+ self .setStyleSheet (f"color: { self .color } " )
1127
+
1128
+ def leaveEvent (self , event ):
1129
+ self .unsetCursor ()
1130
+ self .setStyleSheet (self ._default_style )
1131
+
1132
+
1113
1133
class LabelPair (QWidget ):
1114
1134
def __init__ (self , color : str , name : str , parent : QWidget ):
1115
1135
super ().__init__ (parent )
@@ -1118,7 +1138,7 @@ def __init__(self, color: str, name: str, parent: QWidget):
1118
1138
self ._part_name = name
1119
1139
1120
1140
self .color_label = QLabel ("" , parent = self )
1121
- self .part_label = QLabel (name , parent = self )
1141
+ self .part_label = ClickableLabel (name , color = color , parent = self )
1122
1142
1123
1143
self .color_label .setToolTip (name )
1124
1144
self .part_label .setToolTip (name )
@@ -1178,6 +1198,15 @@ def __init__(self, parent):
1178
1198
1179
1199
self ._build ()
1180
1200
1201
+ @property
1202
+ def labels (self ):
1203
+ labels = []
1204
+ for i in range (self ._layout .count ()):
1205
+ item = self ._layout .itemAt (i )
1206
+ if w := item .widget ():
1207
+ labels .append (w )
1208
+ return labels
1209
+
1181
1210
def _build (self ):
1182
1211
self ._container .setSizePolicy (
1183
1212
QSizePolicy .Fixed , QSizePolicy .Maximum
0 commit comments