Is there a platform independent way to specify a fixed width font for a Qt widget ?
If I set the font to "Monospace" in Designer on Linux, it is not found on Windows and Arial is used instead.
Monospaced fonts are customary on typewriters and for typesetting computer code. Monospaced fonts were widely used in early computers and computer terminals, which often had extremely limited graphical capabilities.
Monospaced typefaces do reduce legibility, albeit by a margin. In Universal Principles of Design, the entry on legibility states: Proportionally spaced typefaces are preferred over monospaced.
Basically, for a font to be considered monospace, every glyph has to be the same width, right down to the exact same number of units. This includes even glyphs that should normally be zero width, or a certain width (such as em spaces, em dashes, etc).
You can use the style hint property of QFont:
QFont font("Monospace"); font.setStyleHint(QFont::TypeWriter);
If the font cannot be found (which happens with Monospace on Windows), Qt's font matching algorithm tries to find a font that matches the given style hint.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With