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.
This commit is contained in:
parent
3a53149a48
commit
f66a0219f6
1 changed files with 3 additions and 6 deletions
|
|
@ -24,20 +24,17 @@
|
||||||
namespace deskflow::gui {
|
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
|
* https://www.qt.io/blog/dark-mode-on-windows-11-with-qt-6.5
|
||||||
*/
|
*/
|
||||||
inline bool isDarkMode()
|
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 QPalette defaultPalette;
|
||||||
const auto text = defaultPalette.color(QPalette::WindowText);
|
const auto text = defaultPalette.color(QPalette::WindowText);
|
||||||
const auto window = defaultPalette.color(QPalette::Window);
|
const auto window = defaultPalette.color(QPalette::Window);
|
||||||
return text.lightness() > window.lightness();
|
return text.lightness() > window.lightness();
|
||||||
#endif // QT_VERSION
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace deskflow::gui
|
} // namespace deskflow::gui
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue