QGtk3Interface: Explicitly add monospace font provider

In case the current GTK3 theme has no monospace font defined, a
monospace font requested by a Qt application can trigger a GTK warning
"Theme parsing error: <data>:1:0: Expected a valid selector".
The warning is triggered by Qt requesting "{font-family: monospace;}".

In this case:
=> ensure fallback to GTK standard monospace font
=> request "* {font-family: monospace;}" to avoid the warning

Task-number: QTBUG-112896
Change-Id: I24a8da62908af9b153245f53026af60e63a600d7
Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
(cherry picked from commit 8d1304f4f2cbc8e7e0f1b9c48236dde548b2bc8d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Axel Spoerl 2023-06-12 14:42:27 +02:00 committed by Qt Cherry-pick Bot
parent 75544c0af6
commit 0fa6b3dcf4

View File

@ -608,7 +608,8 @@ QFont QGtk3Interface::font(QPlatformTheme::Font type) const
GtkCssProvider *cssProvider = nullptr;
if (type == QPlatformTheme::FixedFont) {
cssProvider = gtk_css_provider_new();
const char *fontSpec = "{font-family: monospace;}";
gtk_style_context_add_class (con, GTK_STYLE_CLASS_MONOSPACE);
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);