From 4bec9b90c47d456ba34df879bdb1374873352f99 Mon Sep 17 00:00:00 2001 From: Vladimir Golovnev Date: Fri, 8 Nov 2024 11:45:16 +0300 Subject: [PATCH] Check real palette darkness to detect "dark theme" `QStyleHints::colorScheme()` returns chosen color scheme even if current style doesn't support it and uses different palette. PR #21771. --- src/gui/uithememanager.cpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/gui/uithememanager.cpp b/src/gui/uithememanager.cpp index 4319d3c28..61f2276fc 100644 --- a/src/gui/uithememanager.cpp +++ b/src/gui/uithememanager.cpp @@ -47,16 +47,9 @@ namespace { bool isDarkTheme() { - switch (qApp->styleHints()->colorScheme()) - { - case Qt::ColorScheme::Dark: - return true; - case Qt::ColorScheme::Light: - return false; - default: - // fallback to custom method - return (qApp->palette().color(QPalette::Active, QPalette::Base).lightness() < 127); - } + const QPalette palette = qApp->palette(); + const QColor &color = palette.color(QPalette::Active, QPalette::Base); + return (color.lightness() < 127); } }