From f66a0219f62db075e76f8a0cba2edc9c3a7313c4 Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Thu, 31 Oct 2024 13:31:23 -0400 Subject: [PATCH] fix: isDarkMode Check while newer Qt does provide a method to check if dark mode Its not always correct the old method is Anytime the text is lighter then the window its dark mode. --- src/lib/gui/style_utils.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/lib/gui/style_utils.h b/src/lib/gui/style_utils.h index a9c2d4e99..bf82a3ef6 100644 --- a/src/lib/gui/style_utils.h +++ b/src/lib/gui/style_utils.h @@ -24,20 +24,17 @@ namespace deskflow::gui { /** - * @brief Detects dark mode depending on Qt version. + * @brief Detects dark mode in a universal manner (all Qt versions). + * Until better platform support is added, it's more reliable to use the old way (compare text and window lightness), + * because the newer versions in Qt 6.5+ are not always correct and some return `UnknownScheme`. * https://www.qt.io/blog/dark-mode-on-windows-11-with-qt-6.5 */ inline bool isDarkMode() { -#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) - const auto scheme = QGuiApplication::styleHints()->colorScheme(); - return scheme == Qt::ColorScheme::Dark; -#else const QPalette defaultPalette; const auto text = defaultPalette.color(QPalette::WindowText); const auto window = defaultPalette.color(QPalette::Window); return text.lightness() > window.lightness(); -#endif // QT_VERSION } } // namespace deskflow::gui