mirror of
https://github.com/stenzek/duckstation.git
synced 2026-02-13 18:04:32 +00:00
Qt: Override application font on Linux
Default fonts are ugly and too large.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user