@@ -180,9 +180,8 @@ def widget_drop_shadow(widget: QWidget) -> None:
180180 widget .setGraphicsEffect (shadow )
181181
182182
183- def _embossed_fill (is_down : bool , under_mouse : bool ) -> QColor :
183+ def _embossed_fill (is_down : bool , under_mouse : bool , is_dark : bool ) -> QColor :
184184 """An embossed surface's fill color."""
185- is_dark = is_dark_theme ()
186185 alpha = _EMBOSSED_FILL_ALPHA_DARK if is_dark else _EMBOSSED_FILL_ALPHA_LIGHT
187186 if is_down :
188187 alpha //= 2
@@ -264,12 +263,16 @@ def paint_surface(
264263 is_down : bool = False ,
265264 under_mouse : bool = False ,
266265 style : SurfaceStyle = SurfaceStyle .EMBOSSED ,
266+ always_dark : bool = False ,
267267 ) -> None :
268268
269269 painter .setRenderHint (QPainter .RenderHint .Antialiasing )
270270 strength = _gradient_strength (rect .height (), style )
271- self ._paint_background (painter , rect , radius , is_down , under_mouse , style , strength )
272- self .paint_outlines (painter , rect , radius , is_down , under_mouse , style )
271+ is_dark = always_dark or is_dark_theme ()
272+ self ._paint_background (
273+ painter , rect , radius , is_down , under_mouse , is_dark , style , strength
274+ )
275+ self .paint_outlines (painter , rect , radius , is_down , under_mouse , style , always_dark )
273276
274277 def paint_outlines (
275278 self ,
@@ -279,6 +282,7 @@ def paint_outlines(
279282 is_down : bool = False ,
280283 under_mouse : bool = False ,
281284 style : SurfaceStyle = SurfaceStyle .EMBOSSED ,
285+ always_dark : bool = False ,
282286 ) -> None :
283287 """Paint a surface's inner and outer outlines.
284288
@@ -287,8 +291,11 @@ def paint_outlines(
287291 painter .setRenderHint (QPainter .RenderHint .Antialiasing )
288292 rectf = QRectF (rect ).adjusted (0.5 , 0.5 , - 0.5 , - 0.5 )
289293 strength = _gradient_strength (rect .height (), style )
290- self ._paint_outer_outline (painter , rectf , radius , is_down , under_mouse , style , strength )
291- self ._paint_inner_outline (painter , rectf , radius , is_down , style , strength )
294+ is_dark = always_dark or is_dark_theme ()
295+ self ._paint_outer_outline (
296+ painter , rectf , radius , is_down , under_mouse , is_dark , style , strength
297+ )
298+ self ._paint_inner_outline (painter , rectf , radius , is_down , is_dark , style , strength )
292299
293300 def paint_debossed (self , painter : QPainter , rect : QRect , radius : float , color : QColor ) -> None :
294301 """Paint a colored debossed surface."""
@@ -320,6 +327,7 @@ def _paint_background(
320327 radius : float ,
321328 is_down : bool ,
322329 under_mouse : bool ,
330+ is_dark : bool ,
323331 style : SurfaceStyle = SurfaceStyle .EMBOSSED ,
324332 strength : float = 1.0 ,
325333 ) -> None :
@@ -336,15 +344,15 @@ def _paint_background(
336344 else :
337345 top_alpha = _EMBOSSED_GRADIENT_TOP_ALPHA
338346
339- painter .setBrush (_embossed_fill (is_down , under_mouse ))
347+ painter .setBrush (_embossed_fill (is_down , under_mouse , is_dark ))
340348 painter .drawPath (path )
341349 gradient = QLinearGradient (
342350 rectf .topLeft () if not is_down else rectf .bottomLeft (),
343351 rectf .bottomLeft () if not is_down else rectf .topLeft (),
344352 )
345353 bottom_alpha = (
346354 _EMBOSSED_GRADIENT_BOTTOM_ALPHA_DARK
347- if is_dark_theme ()
355+ if is_dark
348356 else _EMBOSSED_GRADIENT_BOTTOM_ALPHA_LIGHT
349357 )
350358 _set_stops (
@@ -355,9 +363,7 @@ def _paint_background(
355363 elif style == SurfaceStyle .DEBOSSED :
356364 gradient = QLinearGradient (rectf .topLeft (), rectf .bottomLeft ())
357365 top_alpha , bottom_alpha = (
358- _DEBOSSED_GRADIENT_ALPHAS_DARK
359- if is_dark_theme ()
360- else _DEBOSSED_GRADIENT_ALPHAS_LIGHT
366+ _DEBOSSED_GRADIENT_ALPHAS_DARK if is_dark else _DEBOSSED_GRADIENT_ALPHAS_LIGHT
361367 )
362368 _set_stops (
363369 gradient , QColor (0 , 0 , 0 , top_alpha ), QColor (0 , 0 , 0 , bottom_alpha ), strength
@@ -373,6 +379,7 @@ def _paint_outer_outline(
373379 radius : float ,
374380 is_down : bool ,
375381 under_mouse : bool ,
382+ is_dark : bool ,
376383 style : SurfaceStyle = SurfaceStyle .EMBOSSED ,
377384 strength : float = 1.0 ,
378385 ) -> None :
@@ -382,7 +389,7 @@ def _paint_outer_outline(
382389
383390 gradient = QLinearGradient (rect .topLeft (), rect .bottomLeft ())
384391 if style == SurfaceStyle .EMBOSSED :
385- if is_dark_theme () :
392+ if is_dark :
386393 top_alpha , bottom_alpha = _EMBOSSED_OUTER_OUTLINE_ALPHAS_DARK
387394 elif under_mouse and not is_down :
388395 top_alpha , bottom_alpha = _EMBOSSED_OUTER_OUTLINE_ALPHAS_HOVER_LIGHT
@@ -394,7 +401,7 @@ def _paint_outer_outline(
394401 elif style == SurfaceStyle .DEBOSSED :
395402 top_alpha , bottom_alpha = (
396403 _DEBOSSED_OUTER_OUTLINE_ALPHAS_DARK
397- if is_dark_theme ()
404+ if is_dark
398405 else _DEBOSSED_OUTER_OUTLINE_ALPHAS_LIGHT
399406 )
400407 _set_stops (
@@ -417,6 +424,7 @@ def _paint_inner_outline(
417424 rect : QRectF ,
418425 radius : float ,
419426 is_down : bool ,
427+ is_dark : bool ,
420428 style : SurfaceStyle = SurfaceStyle .EMBOSSED ,
421429 strength : float = 1.0 ,
422430 ) -> None :
@@ -434,7 +442,7 @@ def _paint_inner_outline(
434442 if style == SurfaceStyle .EMBOSSED :
435443 top_alpha , bottom_alpha = (
436444 _EMBOSSED_INNER_OUTLINE_ALPHAS_DARK
437- if is_dark_theme ()
445+ if is_dark
438446 else _EMBOSSED_INNER_OUTLINE_ALPHAS_LIGHT
439447 )
440448 _set_stops (
@@ -446,7 +454,7 @@ def _paint_inner_outline(
446454 elif style == SurfaceStyle .DEBOSSED :
447455 top_alpha , bottom_alpha = (
448456 _DEBOSSED_INNER_OUTLINE_ALPHAS_DARK
449- if is_dark_theme ()
457+ if is_dark
450458 else _DEBOSSED_INNER_OUTLINE_ALPHAS_LIGHT
451459 )
452460 _set_stops (
0 commit comments