Skip to content

Commit

Permalink
Use Qt built-in to determine the system's preferred fixed-width font
Browse files Browse the repository at this point in the history
  • Loading branch information
kriswilk authored and chennes committed Oct 16, 2024
1 parent aa78eb3 commit 9806a46
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions src/Gui/PreferencePages/DlgSettingsEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,10 @@ struct DlgSettingsEditorP
namespace
{

/**
* Get some kind of font that is monospaced, suitable for coding.
*
* Based on
* https://stackoverflow.com/questions/18896933/qt-qfont-selection-of-a-monospace-font-doesnt-work
*/
/** Get the system-preferred fixed-width font. */
QFont getMonospaceFont()
{
QFont font(QString::fromLatin1("monospace"));
if (font.fixedPitch()) {
return font;
}
font.setStyleHint(QFont::Monospace);
if (font.fixedPitch()) {
return font;
}
font.setStyleHint(QFont::TypeWriter);
if (font.fixedPitch()) {
return font;
}
font.setFamily(QString::fromLatin1("courier"));
if (font.fixedPitch()) {
return font;
}
return font; // We failed, but return whatever we have anyway
return QFontDatabase::systemFont(QFontDatabase::FixedFont);
}
} // namespace

Expand Down

0 comments on commit 9806a46

Please sign in to comment.