Support Qt below 6.5

QStyleHints::colorScheme is only 6.5+ but github actions latest ubuntu image is running Qt 6.4.
This commit is contained in:
luisangelsm
2026-02-19 19:21:28 +01:00
parent 892d6f3b08
commit 76860ae6c4

View File

@ -4,6 +4,7 @@
#include "theme_factory.h"
#include <QGuiApplication>
#include <QPalette>
#include <QStyleHints>
// 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)