diff options
author | Eike Ziller <eike.ziller@qt.io> | 2021-10-25 15:46:33 +0200 |
---|---|---|
committer | Eike Ziller <eike.ziller@qt.io> | 2021-10-26 13:02:46 +0000 |
commit | d977db303ddd47ca3565f50bcc2423d53990b1ea (patch) | |
tree | 0e012827d32061a9d5efb6da308b075e50943993 | |
parent | 0fc1bb6187fd3297b97f42ede5af3269a1e4ea9d (diff) |
macOS: Force light appearance before saving system palette
When using a light theme while macOS is in dark mode, we need to first
force the application appearance to be light, before saving the system
palette. Otherwise the system palette will contain colors from the dark
system appearance.
Fixes: QTCREATORBUG-21520
Fixes: QTCREATORBUG-26427
Fixes: QTCREATORBUG-26428
Change-Id: Icf802093de17715d16db5c5735b133f2fc465436
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
-rw-r--r-- | src/libs/utils/theme/theme.cpp | 24 | ||||
-rw-r--r-- | src/libs/utils/theme/theme.h | 2 | ||||
-rw-r--r-- | src/plugins/coreplugin/coreplugin.cpp | 7 |
3 files changed, 24 insertions, 9 deletions
diff --git a/src/libs/utils/theme/theme.cpp b/src/libs/utils/theme/theme.cpp index e45662012e..3cb43de469 100644 --- a/src/libs/utils/theme/theme.cpp +++ b/src/libs/utils/theme/theme.cpp @@ -67,20 +67,26 @@ void setThemeApplicationPalette() QApplication::setPalette(m_creatorTheme->palette()); } -void setCreatorTheme(Theme *theme) +static void maybeForceMacOSLight(Theme *theme) { - if (m_creatorTheme == theme) - return; - delete m_creatorTheme; - m_creatorTheme = theme; - #ifdef Q_OS_MACOS // Match the native UI theme and palette with the creator // theme by forcing light aqua for light creator themes. if (theme && !theme->flag(Theme::DarkUserInterface)) Internal::forceMacOSLightAquaApperance(); +#else + Q_UNUSED(theme) #endif +} +void setCreatorTheme(Theme *theme) +{ + if (m_creatorTheme == theme) + return; + delete m_creatorTheme; + m_creatorTheme = theme; + + maybeForceMacOSLight(theme); setThemeApplicationPalette(); } @@ -270,6 +276,12 @@ static QPalette copyPalette(const QPalette &p) return res; } +void Theme::setInitialPalette(Theme *initTheme) +{ + maybeForceMacOSLight(initTheme); + initialPalette(); +} + QPalette Theme::initialPalette() { static QPalette palette = copyPalette(QApplication::palette()); diff --git a/src/libs/utils/theme/theme.h b/src/libs/utils/theme/theme.h index a4fd112786..3af43ed6f9 100644 --- a/src/libs/utils/theme/theme.h +++ b/src/libs/utils/theme/theme.h @@ -481,6 +481,8 @@ public: static bool systemUsesDarkMode(); static QPalette initialPalette(); + static void setInitialPalette(Theme *initTheme); + protected: Theme(Theme *originTheme, QObject *parent = nullptr); ThemePrivate *d; diff --git a/src/plugins/coreplugin/coreplugin.cpp b/src/plugins/coreplugin/coreplugin.cpp index 3043a7dd1e..77875a7ac4 100644 --- a/src/plugins/coreplugin/coreplugin.cpp +++ b/src/plugins/coreplugin/coreplugin.cpp @@ -160,10 +160,11 @@ bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage) return false; } const CoreArguments args = parseArguments(arguments); - Theme::initialPalette(); // Initialize palette before setting it Theme *themeFromArg = ThemeEntry::createTheme(args.themeId); - setCreatorTheme(themeFromArg ? themeFromArg - : ThemeEntry::createTheme(ThemeEntry::themeSetting())); + Theme *theme = themeFromArg ? themeFromArg + : ThemeEntry::createTheme(ThemeEntry::themeSetting()); + Theme::setInitialPalette(theme); // Initialize palette before setting it + setCreatorTheme(theme); InfoBar::initialize(ICore::settings()); new ActionManager(this); ActionManager::setPresentationModeEnabled(args.presentationMode); |