Is there a cross-platform way of getting the user's preferred fixed-width and proportional fonts in Qt?
For example, in Cocoa, there is
NSFont *proportional = [NSFont userFontOfSize:12.0f];
NSFont *fixed_width = [NSFont userFixedPitchFontOfSize:12.0f];
I would like to find an equivalent in Qt that works in Mac, Linux, and Windows.
The system fonts Courier, Menlo, and Consolas are examples of monospaced fonts , so named because every character is the same width. When the characters vary in width, the font is called proportional .
“Arial”, “Helvetica” and “Calibri” are sans serif fonts. Fixed width fonts have, well, fixed widths for each character. This is especially useful to programmers because it makes code easier to read. “Courier New”, “Lucida Console” and “Consolas” are fixed width fonts.
Simply use the setFont() method on the QApplication or QWidget : QFont font("Courier New"); font. setStyleHint(QFont::Monospace); QApplication::setFont(font);
Using QFontDatabase's systemFont(..) function, you can retrieve
Example:
const QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont)
Introduced in Qt 5.2
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