Skip to content

Commit

Permalink
fix: qApp set fixed font not work
Browse files Browse the repository at this point in the history
onFontChanged will send ApplicationFontChange event to
all windows. we stop this opration if qApp set a font

sub menu ==> draw arrow icon ==> QIcon::fromtheme ==>
QIconLoader ==> themeHint(SystemIconThemeName) ==>
appTheme() ==> connect ==> fontNameChanged

Issue: linuxdeepin/dtk#124
  • Loading branch information
kegechen committed Nov 1, 2023
1 parent abd7821 commit fb6410d
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions platformthemeplugin/qdeepintheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,33 @@ static void onIconThemeSetCallback()
}
}

static inline uint resolveMask(const QFont &f)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
return f.resolve();
#else
return f.resolveMask();
#endif
}

static inline void setResolveMask(QFont &f, uint mask)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
return f.resolve(mask);
#else
return f.setResolveMask(mask);
#endif
}

static void onFontChanged()
{
// 插件中初始化 appFont 时会 resolve(0) 即清空 resolve_mask
// 如果用户再主动设置字体会改变 resolve_mask 即 app_font->resolve() > 0
// qApp->setFont(resolvedFont) 将不再响应 xsettings 字体变化
if (QGuiApplicationPrivate::app_font &&
resolveMask(*QGuiApplicationPrivate::app_font))
return;

// 先清理旧的font对象
if (QGuiApplicationPrivate::app_font)
delete QGuiApplicationPrivate::app_font;
Expand Down Expand Up @@ -661,6 +686,7 @@ const QFont *QDeepinTheme::font(QPlatformTheme::Font type) const
sysFont.reset(new QFont(QString()));
sysFont->setFamily(font_name);
sysFont->setPointSizeF(font_size);
setResolveMask(*sysFont, QFont::NoPropertiesResolved);

return sysFont.data();
}
Expand All @@ -686,6 +712,7 @@ const QFont *QDeepinTheme::font(QPlatformTheme::Font type) const
fixedFont.reset(new QFont(QString()));
fixedFont->setFamily(font_name);
fixedFont->setPointSizeF(font_size);
setResolveMask(*fixedFont, QFont::NoPropertiesResolved);

return fixedFont.data();
}
Expand Down

0 comments on commit fb6410d

Please sign in to comment.