diff --git a/example/main.cpp b/example/main.cpp index 76e09765..066e0541 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 f8e5b943..46b810f7 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); }