# HG changeset patch # User Torsten Lilge # Date 1618161749 -7200 # Node ID 82aaf001abee77d1e04cd6e9488a1dd6e75ba818 # Parent d7223245d26f52ddf4ab787625048961fd5fae66 make detection of default fixed font for gui more robust * resource-manager.cc (get_default_font_family): check the system fixed font from the QFontDatabase if it is contained in a QFontComboBox of monospaced fonts, if not, take the first font from the QFontComboBox diff -r d7223245d26f -r 82aaf001abee libgui/src/resource-manager.cc --- a/libgui/src/resource-manager.cc Sat Apr 10 20:58:08 2021 +0200 +++ b/libgui/src/resource-manager.cc Sun Apr 11 19:22:29 2021 +0200 @@ -209,10 +209,6 @@ { QString default_family; -#if defined (Q_OS_MAC) - // Use hard coded default on macOS, since selection of fixed width - // default font is unreliable (see bug #59128). - // Get all available fixed width fonts via a font combobox QFontComboBox font_combo_box; font_combo_box.setFontFilters (QFontComboBox::MonospacedFonts); @@ -221,6 +217,9 @@ for (int index = 0; index < font_combo_box.count(); index++) fonts << font_combo_box.itemText(index); +#if defined (Q_OS_MAC) + // Use hard coded default on macOS, since selection of fixed width + // default font is unreliable (see bug #59128). // Test for macOS default fixed width font if (fonts.contains (global_mono_font.def.toString ())) default_family = global_mono_font.def.toString (); @@ -233,6 +232,14 @@ // Get the system's default monospaced font QFont fixed_font = QFontDatabase::systemFont (QFontDatabase::FixedFont); default_family = fixed_font.defaultFamily (); + + // Since this might be unreliable, test all available fixed width fonts + if (! fonts.contains (default_family)) + { + // Font returned by QFontDatabase is not in fixed fonts list. + // Fallback: take first from this list + default_family = fonts[0]; + } } // Test env variable which has preference