Theme: Use dark theme by default on dark windows

Change-Id: Ieb024e01adfdce1c37948097bae85fa2488ee341
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2021-01-18 08:42:48 +01:00
parent 8192f7f4f4
commit aa974e6816
4 changed files with 19 additions and 3 deletions

View File

@@ -26,6 +26,7 @@
#include "theme.h" #include "theme.h"
#include "theme_p.h" #include "theme_p.h"
#include "../algorithm.h" #include "../algorithm.h"
#include "../hostosinfo.h"
#include "../qtcassert.h" #include "../qtcassert.h"
#ifdef Q_OS_MACOS #ifdef Q_OS_MACOS
#import "theme_mac.h" #import "theme_mac.h"
@@ -242,6 +243,18 @@ void Theme::readSettings(QSettings &settings)
} }
} }
bool Theme::systemUsesDarkMode()
{
if (HostOsInfo::isWindowsHost()) {
constexpr char regkey[]
= "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize";
bool ok;
const auto setting = QSettings(regkey, QSettings::NativeFormat).value("AppsUseLightTheme").toInt(&ok);
return ok && setting == 0;
}
return false;
}
// If you copy QPalette, default values stay at default, even if that default is different // If you copy QPalette, default values stay at default, even if that default is different
// within the context of different widgets. Create deep copy. // within the context of different widgets. Create deep copy.
static QPalette copyPalette(const QPalette &p) static QPalette copyPalette(const QPalette &p)

View File

@@ -394,6 +394,7 @@ public:
void readSettings(QSettings &settings); void readSettings(QSettings &settings);
static bool systemUsesDarkMode();
static QPalette initialPalette(); static QPalette initialPalette();
protected: protected:

View File

@@ -220,6 +220,7 @@ const char SETTINGS_DEFAULT_LINE_TERMINATOR[] = "General/DefaultLineTerminator";
const char SETTINGS_THEME[] = "Core/CreatorTheme"; const char SETTINGS_THEME[] = "Core/CreatorTheme";
const char DEFAULT_THEME[] = "flat"; const char DEFAULT_THEME[] = "flat";
const char DEFAULT_DARK_THEME[] = "flat-dark";
const char TR_CLEAR_MENU[] = QT_TRANSLATE_NOOP("Core", "Clear Menu"); const char TR_CLEAR_MENU[] = QT_TRANSLATE_NOOP("Core", "Clear Menu");

View File

@@ -225,9 +225,10 @@ QList<ThemeEntry> ThemeEntry::availableThemes()
Id ThemeEntry::themeSetting() Id ThemeEntry::themeSetting()
{ {
const Id setting = auto defaultId = Theme::systemUsesDarkMode() ? Constants::DEFAULT_DARK_THEME
Id::fromSetting(ICore::settings()->value(QLatin1String(Constants::SETTINGS_THEME), : Constants::DEFAULT_THEME;
QLatin1String(Constants::DEFAULT_THEME))); const Id setting = Id::fromSetting(
ICore::settings()->value(Constants::SETTINGS_THEME, defaultId));
const QList<ThemeEntry> themes = availableThemes(); const QList<ThemeEntry> themes = availableThemes();
if (themes.empty()) if (themes.empty())