diff --git a/ui/qt/main_application.cpp b/ui/qt/main_application.cpp index 306205a1f7..77188fe8e5 100644 --- a/ui/qt/main_application.cpp +++ b/ui/qt/main_application.cpp @@ -310,12 +310,28 @@ const QFont MainApplication::monospaceFont(bool zoomed) const void MainApplication::setMonospaceFont(const char *font_string) { if (font_string && strlen(font_string) > 0) { - mono_font_.fromString(font_string); - - // Only accept the font name if it actually exists. - if (mono_font_.family() == QFontInfo(mono_font_).family()) { - return; +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) + // Qt 6's QFont::toString returns a value with 16 fields, e.g. + // Consolas,11,-1,5,400,0,0,0,0,0,0,0,0,0,0,1 + // Qt 5's QFont::fromString expects a value with 10 fields, e.g. + // Consolas,10,-1,5,50,0,0,0,0,0 + const char *fs_ptr = font_string; + int comma_count = 0; + while ((fs_ptr = strchr(fs_ptr, ',')) != NULL) { + fs_ptr++; + comma_count++; } + if (comma_count < 10) { +#endif + mono_font_.fromString(font_string); + + // Only accept the font name if it actually exists. + if (mono_font_.family() == QFontInfo(mono_font_).family()) { + return; + } +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) + } +#endif } // https://en.wikipedia.org/wiki/Category:Monospaced_typefaces