From 90959b51cbcafe93923728349a289c9bc7b464e8 Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Sat, 14 Nov 2026 08:46:15 +0100 Subject: [PATCH] fix: only apply superqt's mac slider patch on Qt 5 and macOS 12+ applyMacStylePatch works around QTBUG-98093 (sliders on macOS 12+, fixed in Qt 6.2.3) by restyling the slider with a style sheet. It was applied to every range slider, on any platform and Qt version. Co-Authored-By: Claude Opus 5.5 --- src/magicgui/backends/_qtpy/widgets.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/magicgui/backends/_qtpy/widgets.py b/src/magicgui/backends/_qtpy/widgets.py index 89f26d0c..f2253d93 100644 --- a/src/magicgui/backends/_qtpy/widgets.py +++ b/src/magicgui/backends/_qtpy/widgets.py @@ -3,7 +3,9 @@ from __future__ import annotations import math +import platform import re +import sys import warnings from collections.abc import Callable from contextlib import contextmanager, suppress @@ -31,6 +33,14 @@ from magicgui.widgets._concrete import _LabeledWidget from magicgui.widgets.bases import MenuWidget, Widget +# superqt's workaround for sliders on macOS 12+ with Qt 5 (QTBUG-98093, which Qt +# 6.2.3 fixed): it restyles the sliders, so it's only applied where it's needed +_PATCH_MAC_SLIDERS = ( + qtpy.QT5 + and sys.platform == "darwin" + and int(platform.mac_ver()[0].split(".", maxsplit=1)[0]) >= 12 +) + if TYPE_CHECKING: from collections.abc import Iterable, Iterator, Sequence @@ -979,8 +989,7 @@ class RangeSlider(_Slider): def __init__(self, **kwargs: Any) -> None: super().__init__(superqt.QLabeledRangeSlider, **kwargs) - if hasattr(self._qwidget, "applyMacStylePatch"): - # >= magicgui v0.5.2 + if _PATCH_MAC_SLIDERS: self._qwidget.applyMacStylePatch() def _mgui_set_readout_visibility(self, value: bool): @@ -1009,8 +1018,7 @@ class FloatRangeSlider(RangeSlider): def __init__(self, **kwargs: Any) -> None: _Slider.__init__(self, superqt.QLabeledDoubleRangeSlider, **kwargs) - if hasattr(self._qwidget, "applyMacStylePatch"): - # >= magicgui v0.5.2 + if _PATCH_MAC_SLIDERS: self._qwidget.applyMacStylePatch()