@@ -46,6 +46,8 @@ def toolbarNames(self) -> list[str]:
4646
4747 _toolbars : Mapping [str , qt .QToolBar ] = {}
4848
49+ _slicerDefaultPalette : Optional [qt .QPalette ] = None
50+
4951 def __init__ (self , parent : Optional [qt .QWidget ]):
5052 """Called when the application opens the module the first time and the widget is initialized."""
5153 ScriptedLoadableModuleWidget .__init__ (self , parent )
@@ -70,6 +72,8 @@ def setup(self):
7072 # See https://github.com/KitwareMedical/SlicerCustomAppTemplate/issues/72
7173 self .uiWidget .setPalette (slicer .util .mainWindow ().style ().standardPalette ())
7274
75+ self ._slicerDefaultPalette = slicer .app .palette ()
76+
7377 # Remove unneeded UI elements
7478 self .modifyWindowUI ()
7579 self .setCustomUIVisible (True )
@@ -134,7 +138,10 @@ def toggleStyle(self, visible: bool):
134138 if visible :
135139 self .applyApplicationStyle ()
136140 else :
141+ # Modern Qt controls use Qt Stylesheets (.qss) to control dynamic styling
137142 slicer .app .styleSheet = ""
143+ # Legacy Qt-derived controls (see CTK controls) use Qt palettes for styling
144+ slicer .app .setPalette (self ._slicerDefaultPalette )
138145
139146 def raiseSettings (self , _ ):
140147 self .settingsDialog .exec ()
@@ -144,9 +151,20 @@ def setCustomUIVisible(self, visible: bool):
144151
145152 def applyApplicationStyle (self ):
146153 SlicerCustomAppUtilities .applyStyle ([slicer .app ], self .resourcePath ("Home.qss" ))
154+ self .applyApplicationPalette ()
147155 self .styleThreeDWidget ()
148156 self .styleSliceWidgets ()
149157
158+ def applyApplicationPalette (self ):
159+ """Apply custom palette colors to the application as a workaround for restyling
160+ custom CTK and qMRML controls that do not yet respect Qt stylesheets.
161+ """
162+ highlightColor = qt .QColor ("#009D49" ) # Kitware - Green
163+
164+ p = self ._slicerDefaultPalette
165+ p .setColor (qt .QPalette .Highlight , highlightColor )
166+ slicer .app .setPalette (p )
167+
150168 def styleThreeDWidget (self ):
151169 viewNode = slicer .app .layoutManager ().threeDWidget (0 ).mrmlViewNode () # noqa: F841
152170 # viewNode.SetBackgroundColor(0.0, 0.0, 0.0)
0 commit comments