8

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.

squidpickles
  • 1,737
  • 19
  • 27
  • 2
    I think these should help: [Specify font](http://stackoverflow.com/questions/1468022/how-to-specify-monospace-fonts-for-cross-platform-qt-applications) and [Check if fixed width](http://stackoverflow.com/questions/10977259/qt-fixed-width-font) – Matthew Jul 13 '12 at 20:46
  • @Matthew: almost. They will get a fixed font, but not the system default. For example, on my Mac, the default fixed font is Monaco, but using `QFont font("Monospace"); font.setStyleHint(QFont::TypeWriter);` gets me Courier. – squidpickles Jul 16 '12 at 19:31

1 Answers1

13

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

f15h
  • 776
  • 8
  • 5