QGtk3Theme: Improve fixed font delivery
The gtk_fixed widget was used as a reference to obtain a fixed font and HeaderViewFont. This is a mistake, because the gtk_fixed widget is a container for other widgets with fixed geometries and no layouting. This patch makes the default style being used for a fixed font and, as a drive-by, the combo box as a reference for a header view font. A monospace based css provider as explicitly added to the style context, in case a fixed font is requested. The provider is removed afterwards. Task-number: QTBUG-112896 Pick-to: 6.5 Change-Id: I6bfb2ee9e7befdd2102bdcc6e53ced954a024034 Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
parent
25fcded977
commit
034a071bda
@ -537,13 +537,13 @@ inline constexpr QGtk3Interface::QGtkWidget QGtk3Interface::toWidgetType(QPlatfo
|
|||||||
case QPlatformTheme::ToolButtonFont: return QGtkWidget::gtk_button;
|
case QPlatformTheme::ToolButtonFont: return QGtkWidget::gtk_button;
|
||||||
case QPlatformTheme::ItemViewFont: return QGtkWidget::gtk_entry;
|
case QPlatformTheme::ItemViewFont: return QGtkWidget::gtk_entry;
|
||||||
case QPlatformTheme::ListViewFont: return QGtkWidget::gtk_tree_view;
|
case QPlatformTheme::ListViewFont: return QGtkWidget::gtk_tree_view;
|
||||||
case QPlatformTheme::HeaderViewFont: return QGtkWidget::gtk_fixed;
|
case QPlatformTheme::HeaderViewFont: return QGtkWidget::gtk_combo_box;
|
||||||
case QPlatformTheme::ListBoxFont: return QGtkWidget::gtk_Default;
|
case QPlatformTheme::ListBoxFont: return QGtkWidget::gtk_Default;
|
||||||
case QPlatformTheme::ComboMenuItemFont: return QGtkWidget::gtk_combo_box;
|
case QPlatformTheme::ComboMenuItemFont: return QGtkWidget::gtk_combo_box;
|
||||||
case QPlatformTheme::ComboLineEditFont: return QGtkWidget::gtk_combo_box_text;
|
case QPlatformTheme::ComboLineEditFont: return QGtkWidget::gtk_combo_box_text;
|
||||||
case QPlatformTheme::SmallFont: return QGtkWidget::gtk_Default;
|
case QPlatformTheme::SmallFont: return QGtkWidget::gtk_Default;
|
||||||
case QPlatformTheme::MiniFont: return QGtkWidget::gtk_Default;
|
case QPlatformTheme::MiniFont: return QGtkWidget::gtk_Default;
|
||||||
case QPlatformTheme::FixedFont: return QGtkWidget::gtk_fixed;
|
case QPlatformTheme::FixedFont: return QGtkWidget::gtk_Default;
|
||||||
case QPlatformTheme::GroupBoxTitleFont: return QGtkWidget::gtk_Default;
|
case QPlatformTheme::GroupBoxTitleFont: return QGtkWidget::gtk_Default;
|
||||||
case QPlatformTheme::TabButtonFont: return QGtkWidget::gtk_button;
|
case QPlatformTheme::TabButtonFont: return QGtkWidget::gtk_button;
|
||||||
case QPlatformTheme::EditorFont: return QGtkWidget::gtk_entry;
|
case QPlatformTheme::EditorFont: return QGtkWidget::gtk_entry;
|
||||||
@ -604,6 +604,24 @@ QFont QGtk3Interface::font(QPlatformTheme::Font type) const
|
|||||||
if (!con)
|
if (!con)
|
||||||
return QFont();
|
return QFont();
|
||||||
|
|
||||||
|
// explicitly add provider for fixed font
|
||||||
|
GtkCssProvider *cssProvider = nullptr;
|
||||||
|
if (type == QPlatformTheme::FixedFont) {
|
||||||
|
cssProvider = gtk_css_provider_new();
|
||||||
|
const char *fontSpec = "{font-family: monospace;}";
|
||||||
|
gtk_css_provider_load_from_data(cssProvider, fontSpec, -1, NULL);
|
||||||
|
gtk_style_context_add_provider(con, GTK_STYLE_PROVIDER(cssProvider),
|
||||||
|
GTK_STYLE_PROVIDER_PRIORITY_USER);
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove monospace provider from style context and unref it
|
||||||
|
QScopeGuard guard([&](){
|
||||||
|
if (cssProvider) {
|
||||||
|
gtk_style_context_remove_provider(con, GTK_STYLE_PROVIDER(cssProvider));
|
||||||
|
g_object_unref(cssProvider);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const PangoFontDescription *gtkFont = gtk_style_context_get_font(con, GTK_STATE_FLAG_NORMAL);
|
const PangoFontDescription *gtkFont = gtk_style_context_get_font(con, GTK_STATE_FLAG_NORMAL);
|
||||||
if (!gtkFont)
|
if (!gtkFont)
|
||||||
return QFont();
|
return QFont();
|
||||||
@ -630,6 +648,7 @@ QFont QGtk3Interface::font(QPlatformTheme::Font type) const
|
|||||||
font.setFamily("monospace"_L1);
|
font.setFamily("monospace"_L1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return font;
|
return font;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user