Qt: Override application font on Linux

Default fonts are ugly and too large.
This commit is contained in:
Stenzek
2025-12-16 23:26:48 +10:00
parent 6521355343
commit b8b576e158
2 changed files with 26 additions and 5 deletions

View File

@@ -257,6 +257,14 @@ bool QtHost::EarlyProcessStartup()
return false;
}
#ifdef __linux__
// Fonts on Linux are ugly and too large. This is only part of where we apply it, see qtthemes.cpp for the rest.
QFont application_font = QGuiApplication::font();
application_font.setFamilies(GetRobotoFontFamilies());
application_font.setPixelSize(12);
QApplication::setFont(application_font);
#endif
return true;
}

View File

@@ -18,6 +18,7 @@ namespace QtHost {
static void SetThemeAttributes(bool is_stylesheet_theme, bool is_variable_color_theme, bool is_dark_theme);
static bool NativeThemeStylesheetNeedsUpdate();
static void SetStyleFromSettings();
static void SetStyleSheet(const QString& stylesheet);
static QString GetNativeThemeStylesheet();
namespace {
@@ -70,12 +71,24 @@ void QtHost::SetThemeAttributes(bool is_stylesheet_theme, bool is_variable_color
qApp->styleHints()->setColorScheme(is_dark_theme ? Qt::ColorScheme::Dark : Qt::ColorScheme::Light);
}
void QtHost::SetStyleSheet(const QString& stylesheet)
{
#ifdef __linux__
// Fonts on Linux are ugly and too large. Unfortunately QApplication::setFont() doesn't seem to apply to
// all widgets, so instead we have to jankily prefix it to all stylesheets.
qApp->setStyleSheet(QStringLiteral("QMenu, QMenuBar { font-family: \"Roboto\"; font-size: 12px; }\n") + stylesheet);
#else
qApp->setStyleSheet(stylesheet);
#endif
}
void QtHost::SetStyleFromSettings()
{
const TinyString theme = Host::GetBaseTinyStringSettingValue("UI", "Theme", QtHost::GetDefaultThemeName());
// Clear any existing stylesheet before applying new.
qApp->setStyleSheet(QString());
// Clear any existing stylesheet before applying new. Avoids half-painted windows when changing themes.
if (s_state.is_stylesheet_theme)
SetStyleSheet(QString());
if (theme == "qdarkstyle")
{
@@ -85,7 +98,7 @@ void QtHost::SetStyleFromSettings()
QFile f(QStringLiteral(":qdarkstyle/style.qss"));
if (f.open(QFile::ReadOnly | QFile::Text))
qApp->setStyleSheet(f.readAll());
SetStyleSheet(f.readAll());
}
else if (theme == "fusion")
{
@@ -583,7 +596,7 @@ QTextBrowser {
}
)");
qApp->setStyleSheet(stylesheet);
SetStyleSheet(stylesheet);
}
else if (theme == "cobaltsky")
{
@@ -838,7 +851,7 @@ QTextBrowser {
// Cleared above.
if (!stylesheet.isEmpty())
qApp->setStyleSheet(stylesheet);
SetStyleSheet(stylesheet);
}
}