From 76860ae6c446b77a18f6fd488dfe6dabe89fbdb8 Mon Sep 17 00:00:00 2001 From: luisangelsm Date: Thu, 19 Feb 2026 19:21:28 +0100 Subject: [PATCH] Support Qt below 6.5 QStyleHints::colorScheme is only 6.5+ but github actions latest ubuntu image is running Qt 6.4. --- common/themes/theme_manager.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/common/themes/theme_manager.cpp b/common/themes/theme_manager.cpp index 081a7147..e39554be 100644 --- a/common/themes/theme_manager.cpp +++ b/common/themes/theme_manager.cpp @@ -4,6 +4,7 @@ #include "theme_factory.h" #include +#include #include // TODO: add API to force color scheme //styleHints->setColorScheme(Qt::ColorScheme::Dark); @@ -20,6 +21,8 @@ ThemeManager &ThemeManager::instance() void ThemeManager::initialize() { + // QStyleHints::colorScheme is only 6.5+ +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) auto *styleHints = qGuiApp->styleHints(); auto colorScheme = styleHints->colorScheme(); @@ -32,6 +35,15 @@ void ThemeManager::initialize() applyColorScheme(colorScheme); connect(styleHints, &QStyleHints::colorSchemeChanged, this, applyColorScheme, Qt::QueuedConnection); +#else + auto applyPalette = [this](const QPalette &palette) { + setTheme(palette.color(QPalette::Window).lightness() < 128 ? ThemeId::Dark : ThemeId::Light); + }; + + applyPalette(qGuiApp->palette()); + + connect(qGuiApp, &QGuiApplication::paletteChanged, this, applyPalette, Qt::QueuedConnection); +#endif } void ThemeManager::setTheme(ThemeId themeId)