Qt logo


Font Matching


The QFont class is an abstract specification of an ideal font. This font must be matched to fit an actual window system font when drawing is to be done. This is not a trivial operation since there are no fonts that we can be sure will be available on all window systems at all times, or even on a single window system at all times. Qt queries the window system for available fonts and uses a font matching algorithm to decide which one of the available fonts closely matches the QFont settings.

The font matching algorithm works as follows:

First an available font family is found. If the requested is not available the style hint is used to select a replacement family. If the style hint has not been set, "helvetica" will be used.

If even the replacement family is not found, "helvetica" is searched for, if that too is not found Qt will search for a last resort font, i.e. a specific font to match to, ignoring the attribute settings. Qt searches through a built-in list of very common fonts. If none of these are available, Qt chickens out, gives you an error message and aborts (of course this only happens if you are using fonts and Qt has to load a font). We have not been able to find a case where this happens. Please mail us if you do, preferably with a list of the fonts you have installed (under X windows, type "xlsfonts").

The following attributes are then matched, in order of priority:

  1. character set
  2. pitch
  3. point size
  4. weight
  5. italic

If, for example, a font with the correct character set is found, but with all other attributes in the list unmatched, it will be chosen before a font with the wrong character set but with all other attributes correct.

The point size is defined to match if it is within 20% of the requested point size. Of course, when several fonts match and only point size differs the closest point size to the one requested will be chosen.

Using the correct font family has higher priority than using the correct character set.


Copyright © 1999 Troll TechTrademarks
Qt version 2.0.2