From ae549bf94817fa75a11566f88ef50db1cad93dce Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sun, 13 Aug 2023 19:58:58 +0300 Subject: [PATCH] Activate custom stylesheet to mimic dark mode on Qt versions those do not support native dark mode. --- src/libs/vmisc/theme/vtheme.cpp | 59 ++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 8 deletions(-) diff --git a/src/libs/vmisc/theme/vtheme.cpp b/src/libs/vmisc/theme/vtheme.cpp index 5da45f933..f49421615 100644 --- a/src/libs/vmisc/theme/vtheme.cpp +++ b/src/libs/vmisc/theme/vtheme.cpp @@ -217,13 +217,60 @@ void ActivateCustomDarkTheme() } } +//--------------------------------------------------------------------------------------------------------------------- +#if defined(Q_OS_WIN) +void ActivateDefaultThemeWin() +{ +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) + qApp->setStyleSheet(QString()); // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast) +#else + if (VTheme::IsInDarkTheme()) + { + ActivateCustomDarkTheme(); + } + else + { + ActivateCustomLightTheme(); + } +#endif // QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) +} +#endif // defined(Q_OS_WIN) + +//--------------------------------------------------------------------------------------------------------------------- +#if defined(Q_OS_MACX) +void ActivateDefaultThemeMac() +{ +#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0) + qApp->setStyleSheet(QString()); // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast) +#else + if (VTheme::IsInDarkTheme()) + { + ActivateCustomDarkTheme(); + } + else + { + ActivateCustomLightTheme(); + } +#endif // QT_VERSION >= QT_VERSION_CHECK(5, 12, 0) +} +#endif // defined(Q_OS_MACX) + //--------------------------------------------------------------------------------------------------------------------- void ActivateDefaultTheme() { - qApp->setStyleSheet(QString()); // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast) - -#if defined(Q_OS_MACX) - NSMacSetToAutoTheme(); +#if defined(Q_OS_WIN) + ActivateDefaultThemeWin(); +#elif defined(Q_OS_MACX) + ActivateDefaultThemeMac(); +#else + if (VTheme::IsInDarkTheme()) + { + ActivateCustomDarkTheme(); + } + else + { + ActivateCustomLightTheme(); + } #endif } @@ -466,10 +513,6 @@ void VTheme::InitThemeMode() { ActivateCustomDarkTheme(); } - else - { - ActivateCustomLightTheme(); - } } } }