|  | Home · Overviews · Examples |

# QFontDatabase Class Reference
[com.trolltech.qt.gui module]

The `QFontDatabase` class provides information about the fonts available in the underlying window system. More...

## Detailed Description

The `QFontDatabase` class provides information about the fonts available in the underlying window system.

The most common uses of this class are to query the database for the list of font `families` and for the `pointSizes` and `styles` that are available for each family. An alternative to `pointSizes` is `smoothSizes` which returns the sizes at which a given family and style will look attractive.

If the font family is available from two or more foundries the foundry name is included in the family name, e.g. "Helvetica [Adobe]" and "Helvetica [Cronyx]". When you specify a family you can either use the old hyphenated Qt 2.x "foundry-family" format, e.g. "Cronyx-Helvetica", or the new bracketed Qt 3.x "family [foundry]" format e.g. "Helvetica [Cronyx]". If the family has a foundry it is always returned, e.g. by `families`, using the bracketed format.

The `font` function returns a `QFont` given a family, style and point size.

A family and style combination can be checked to see if it is `italic` or `bold`, and to retrieve its `weight`. Similarly we can call `isBitmapScalable`, `isSmoothlyScalable`, `isScalable` and `isFixedPitch`.

Use the `styleString` to obtain a text version of a style.

The `QFontDatabase` class also supports some static functions, for example, `standardSizes`. You can retrieve the description of a writing system using `writingSystemName`, and a sample of characters in a writing system with `writingSystemSample`.

Example:

            QFontDatabase database;
            QTreeWidget fontTree;
            fontTree.setColumnCount(2);
            fontTree.setHeaderLabels(QStringList() << "Font" << "Smooth Sizes");

            foreach (QString family, database.families()) {
                QTreeWidgetItem *familyItem = new QTreeWidgetItem(&fontTree);
                familyItem->setText(0, family);

                foreach (QString style, database.styles(family)) {
                    QTreeWidgetItem *styleItem = new QTreeWidgetItem(familyItem);
                    styleItem->setText(0, style);

                    QString sizes;
                    foreach (int points, database.smoothSizes(family, style))
                        sizes += QString::number(points) + " ";

                    styleItem->setText(1, sizes.trimmed());
                }
            }

This example gets the list of font families, the list of styles for each family, and the point sizes that are available for each combination of family and style, displaying this information in a tree view.

See also `QFont`, `QFontInfo`, `QFontMetrics`, `QFontComboBox`, and Character Map Example.