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.
This commit is contained in:
Vladimir Golovnev 2024-11-08 11:45:16 +03:00 committed by Vladimir Golovnev (Glassez)
parent 5e105b0348
commit 39b965af48
No known key found for this signature in database
GPG key ID: 52A2C7DEE2DFA6F7

View file

@ -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);
}
}