From aba33c4d1f2eee297d41ec39826525120d079173 Mon Sep 17 00:00:00 2001 From: zhuzichu Date: Thu, 20 Apr 2023 00:15:13 +0800 Subject: [PATCH] update --- example/main.cpp | 2 ++ src/FluTheme.cpp | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/example/main.cpp b/example/main.cpp index 76e0976..066e054 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -12,6 +12,8 @@ int main(int argc, char *argv[]) { //将样式设置为Basic,不然会导致组件显示异常 qputenv("QT_QUICK_CONTROLS_STYLE","Basic"); + //6.4及以下监听系统深色模式变化 + qputenv("QT_QPA_PLATFORM","windows:darkmode=2"); QCoreApplication::setOrganizationName("ZhuZiChu"); QCoreApplication::setOrganizationDomain("https://zhuzichu520.github.io"); QCoreApplication::setApplicationName("FluentUI"); diff --git a/src/FluTheme.cpp b/src/FluTheme.cpp index f8e5b94..46b810f 100644 --- a/src/FluTheme.cpp +++ b/src/FluTheme.cpp @@ -34,6 +34,7 @@ bool FluTheme::eventFilter(QObject *obj, QEvent *event) Q_UNUSED(obj); if (event->type() == QEvent::ApplicationPaletteChange) { + qDebug()<<"--------->"; Q_EMIT darkChanged(); event->accept(); return true; @@ -43,7 +44,7 @@ bool FluTheme::eventFilter(QObject *obj, QEvent *event) bool FluTheme::systemDark() { - QPalette palette = (qobject_cast(QCoreApplication::instance()))->palette(); + QPalette palette = (qobject_cast(QGuiApplication::instance()))->palette(); QColor color = palette.color(QPalette::Window).rgb(); return !(color.red() * 0.2126 + color.green() * 0.7152 + color.blue() * 0.0722 > 255 / 2); }