Skip to content

Commit

Permalink
fix: palette refresh delayed in qt6
Browse files Browse the repository at this point in the history
QGuiApplication::paletteChanged is deprecated in qt6,
Delay to emit themeTypeChanged signal, palette doesn't refresh
after sending ThemeChangeEvent.

pms: BUG-303929
  • Loading branch information
18202781743 committed Mar 6, 2025
1 parent c52610f commit 0a0182f
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/kernel/dguiapplicationhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,18 @@ class Q_DECL_HIDDEN GuiApplicationEventFilter : public QObject
}
virtual bool eventFilter(QObject *watched, QEvent *event) override
{
if (watched != qApp)
return QObject::eventFilter(watched, event);

switch(event->type()) {
case QEvent::ApplicationFontChange: {
const QFont font(qGuiApp->font());
m_transmitter->q_func()->fontChanged(font);
} break;
case QEvent::ApplicationPaletteChange: {
m_transmitter->onApplicationPaletteChanged();
break;
}
default:
break;
}
Expand Down Expand Up @@ -269,11 +276,10 @@ void DGuiApplicationHelperPrivate::initApplication(QGuiApplication *app)
app->installEventFilter(new GuiApplicationEventFilter(this, app));
#else
q->connect(app, &QGuiApplication::fontChanged, q, &DGuiApplicationHelper::fontChanged);
#endif
// TODO handle event in qt6.
q->connect(app, &QGuiApplication::paletteChanged, q, [this] {
onApplicationPaletteChanged();
});
#endif

if (Q_UNLIKELY(!appTheme)) { // 此时说明appTheme可能已经被初始化为了systemtheme
if (QGuiApplicationPrivate::is_app_running) {
Expand Down Expand Up @@ -371,11 +377,13 @@ void DGuiApplicationHelperPrivate::notifyAppThemeChanged()
{
D_Q(DGuiApplicationHelper);
notifyAppThemeChangedByEvent();
// 通知主题类型发生变化, 此处可能存在误报的行为, 不过不应该对此做额外的约束
// 此信号的行为应当等价于 applicationPaletteChanged
Q_EMIT q->themeTypeChanged(q->themeType());
// 通知调色板对象的改变
Q_EMIT q->applicationPaletteChanged();
QMetaObject::invokeMethod(q, [q] () {
// 通知主题类型发生变化, 此处可能存在误报的行为, 不过不应该对此做额外的约束
// 此信号的行为应当等价于 applicationPaletteChanged
Q_EMIT q->themeTypeChanged(q->themeType());
// 通知调色板对象的改变
Q_EMIT q->applicationPaletteChanged();
}, Qt::QueuedConnection);
}

void DGuiApplicationHelperPrivate::notifyAppThemeChangedByEvent()
Expand Down

0 comments on commit 0a0182f

Please sign in to comment.