From 3ee7a9f85c9d4566223f44f7bab04abafdfca82c Mon Sep 17 00:00:00 2001 From: Santhosh Kumar Date: Fri, 18 Nov 2022 18:24:10 +0100 Subject: [PATCH] Let styles indicate that they support dark mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a style hint that allows styles to indicate that they support dark mode. The macOS and Fusion styles support dark mode, the other styles, in particular the Windows Vista style, do not. Task-number: QTBUG-72028 Change-Id: I02cac2e19a21898663f50f09a4ef419a613a73ec Reviewed-by: Tor Arne Vestbø --- src/plugins/styles/mac/qmacstyle_mac.mm | 3 +++ src/plugins/styles/windowsvista/qwindowsvistastyle.cpp | 4 ++++ src/widgets/styles/qcommonstyle.cpp | 1 + src/widgets/styles/qfusionstyle.cpp | 1 + src/widgets/styles/qstyle.cpp | 7 +++++++ src/widgets/styles/qstyle.h | 1 + 6 files changed, 17 insertions(+) diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index 975c2f435d..37d1f17a4f 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -2892,6 +2892,9 @@ int QMacStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *w case SH_TabBar_AllowWheelScrolling: ret = false; break; + case SH_SupportsDarkAppearance: + ret = true; + break; default: ret = QCommonStyle::styleHint(sh, opt, w, hret); break; diff --git a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp index 5533a194ac..283a5bdaa9 100644 --- a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp +++ b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp @@ -2316,6 +2316,10 @@ int QWindowsVistaStyle::styleHint(StyleHint hint, const QStyleOption *option, co ret = 1; break; + case SH_SupportsDarkAppearance: + ret = 0; + break; + default: ret = QWindowsStyle::styleHint(hint, option, widget, returnData); break; diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index c7dee0549e..7fe848d9c0 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -5407,6 +5407,7 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget case SH_ItemView_PaintAlternatingRowColorsForEmptyArea: case SH_ComboBox_UseNativePopup: case SH_Table_AlwaysDrawLeftTopGridLines: + case SH_SupportsDarkAppearance: ret = false; break; case SH_MenuBar_AltKeyNavigation: diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index dccfbd8aac..966bd47380 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -3630,6 +3630,7 @@ int QFusionStyle::styleHint(StyleHint hint, const QStyleOption *option, const QW case SH_MenuBar_MouseTracking: case SH_Menu_MouseTracking: case SH_Menu_SupportsSections: + case SH_SupportsDarkAppearance: return 1; #if defined(QT_PLATFORM_UIKIT) diff --git a/src/widgets/styles/qstyle.cpp b/src/widgets/styles/qstyle.cpp index c04b4c1aeb..e5025a05ea 100644 --- a/src/widgets/styles/qstyle.cpp +++ b/src/widgets/styles/qstyle.cpp @@ -1987,6 +1987,13 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, not when the header is hidden. Defaults to false. This enum value has been introduced in Qt 6.3. + \value SH_SupportsDarkAppearance + Determines whether the style is able to render a UI correctly with + a dark palette. Defaults to false. Style implementors should return true + if they have tested the style with a palette where the background colors + are darker than the foreground colors. + This enum value has been introduced in Qt 6.5. + \sa styleHint() */ diff --git a/src/widgets/styles/qstyle.h b/src/widgets/styles/qstyle.h index 23a5bd5ac2..f47c44d7bd 100644 --- a/src/widgets/styles/qstyle.h +++ b/src/widgets/styles/qstyle.h @@ -702,6 +702,7 @@ public: SH_TabBar_AllowWheelScrolling, SH_Table_AlwaysDrawLeftTopGridLines, SH_SpinBox_SelectOnStep, + SH_SupportsDarkAppearance, // Add new style hint values here SH_CustomBase = 0xf0000000