Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default fixed-width font in Qt

Tags:

fonts

qt

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.

like image 518
squidpickles Avatar asked Jul 13 '12 20:07

squidpickles


People also ask

Is courier new a fixed width font?

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 .

Is calibri a fixed width font?

“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.

How do I change the font in Qt?

Simply use the setFont() method on the QApplication or QWidget : QFont font("Courier New"); font. setStyleHint(QFont::Monospace); QApplication::setFont(font);


1 Answers

Using QFontDatabase's systemFont(..) function, you can retrieve

  • the system's default font
  • the default fixed font
  • the "title" font
  • the smallest readable font

Example:

const QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont)

Introduced in Qt 5.2

like image 148
f15h Avatar answered Nov 07 '22 23:11

f15h