mirror of
https://github.com/YACReader/yacreader
synced 2026-03-01 10:22:58 -05:00
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:
@ -4,6 +4,7 @@
|
|||||||
#include "theme_factory.h"
|
#include "theme_factory.h"
|
||||||
|
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
|
#include <QPalette>
|
||||||
#include <QStyleHints>
|
#include <QStyleHints>
|
||||||
|
|
||||||
// TODO: add API to force color scheme //styleHints->setColorScheme(Qt::ColorScheme::Dark);
|
// TODO: add API to force color scheme //styleHints->setColorScheme(Qt::ColorScheme::Dark);
|
||||||
@ -20,6 +21,8 @@ ThemeManager &ThemeManager::instance()
|
|||||||
|
|
||||||
void ThemeManager::initialize()
|
void ThemeManager::initialize()
|
||||||
{
|
{
|
||||||
|
// QStyleHints::colorScheme is only 6.5+
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
|
||||||
auto *styleHints = qGuiApp->styleHints();
|
auto *styleHints = qGuiApp->styleHints();
|
||||||
|
|
||||||
auto colorScheme = styleHints->colorScheme();
|
auto colorScheme = styleHints->colorScheme();
|
||||||
@ -32,6 +35,15 @@ void ThemeManager::initialize()
|
|||||||
applyColorScheme(colorScheme);
|
applyColorScheme(colorScheme);
|
||||||
|
|
||||||
connect(styleHints, &QStyleHints::colorSchemeChanged, this, applyColorScheme, Qt::QueuedConnection);
|
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)
|
void ThemeManager::setTheme(ThemeId themeId)
|
||||||
|
|||||||
Reference in New Issue
Block a user