From f0bcb07ff7a6a37e4842961c5a1f3900af66c97c Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Mon, 25 Nov 2024 02:08:22 +0100 Subject: [PATCH] UI/Qt: Fall back to luma dark mode detection for unknown color scheme The Qt style hints' color scheme can return ::Unknown, in which case we still need to fall back to our 'old' method of using the luma component of the background role color. --- UI/Qt/main.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/UI/Qt/main.cpp b/UI/Qt/main.cpp index cee83fed1d9..92ef4b28052 100644 --- a/UI/Qt/main.cpp +++ b/UI/Qt/main.cpp @@ -37,19 +37,17 @@ bool is_using_dark_system_theme(QWidget&); bool is_using_dark_system_theme(QWidget& widget) { #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) - // We use that only for fallback mode - Q_UNUSED(widget); - // Use the new Qt API available from version 6.5.0 + // Use the explicitly set or system default color scheme whenever available auto color_scheme = QGuiApplication::styleHints()->colorScheme(); - return color_scheme == Qt::ColorScheme::Dark; -#else - // Fallback for older Qt versions + if (color_scheme != Qt::ColorScheme::Unknown) + return color_scheme == Qt::ColorScheme::Dark; +#endif + // Calculate luma based on Rec. 709 coefficients // https://en.wikipedia.org/wiki/Rec._709#Luma_coefficients auto color = widget.palette().color(widget.backgroundRole()); auto luma = 0.2126f * color.redF() + 0.7152f * color.greenF() + 0.0722f * color.blueF(); return luma <= 0.5f; -#endif } }