Skip to content

Commit 0bc7beb

Browse files
committed
Use Qt 6.5 styleHint colorScheme to detect dark theme
- keep linux compatibility WE2-826 Signed-off-by: Raul Metsma <raul@metsma.ee>
1 parent 031d518 commit 0bc7beb

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

src/controller/application.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <QPalette>
3434
#include <QProcess>
3535
#include <QSettings>
36+
#include <QStyleHints>
3637
#include <QTranslator>
3738

3839
inline CommandWithArguments::second_type parseArgumentJson(const QString& argumentStr)
@@ -74,19 +75,17 @@ Application::Application(int& argc, char** argv, const QString& name) :
7475
#endif
7576
}
7677

77-
#ifndef Q_OS_MAC
7878
bool Application::isDarkTheme()
7979
{
80-
#ifdef Q_OS_WIN
81-
QSettings settings(
82-
"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
83-
QSettings::NativeFormat);
84-
return settings.value("AppsUseLightTheme", 1).toInt() == 0;
80+
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
81+
return styleHints()->colorScheme() == Qt::ColorScheme::Dark;
8582
#else
86-
// There is currently no straightforward way to detect dark mode in Linux, but this works for supported OS-s.
83+
// There is currently no straightforward way to detect dark mode in Linux, but this works for
84+
// supported OS-s.
8785
static const bool isDarkTheme = [] {
8886
QProcess p;
89-
p.start(QStringLiteral("gsettings"), {"get", "org.gnome.desktop.interface", "color-scheme"});
87+
p.start(QStringLiteral("gsettings"),
88+
{"get", "org.gnome.desktop.interface", "color-scheme"});
9089
if (p.waitForFinished()) {
9190
return p.readAllStandardOutput().contains("dark");
9291
}
@@ -97,7 +96,6 @@ bool Application::isDarkTheme()
9796
return isDarkTheme;
9897
#endif
9998
}
100-
#endif
10199

102100
void Application::loadTranslations(const QString& lang)
103101
{

src/controller/application.mm

-7
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@
2727
#import <AppKit/AppKit.h>
2828
#import <Cocoa/Cocoa.h>
2929

30-
bool Application::isDarkTheme()
31-
{
32-
auto appearance = [NSApp.effectiveAppearance bestMatchFromAppearancesWithNames:
33-
@[ NSAppearanceNameAqua, NSAppearanceNameDarkAqua ]];
34-
return [appearance isEqualToString:NSAppearanceNameDarkAqua];
35-
}
36-
3730
void Application::showAbout()
3831
{
3932
NSLog(@"web-eid-app: starting app");

0 commit comments

Comments
 (0)