Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: qApp set fixed font not work #199

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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