Home · Overviews · Examples 

QFontMetricsF Class Reference
[com.trolltech.qt.gui module]

The QFontMetricsF class provides font metrics information. More...


Detailed Description

The QFontMetricsF class provides font metrics information.

QFontMetricsF functions calculate the size of characters and strings for a given font. You can construct a QFontMetricsF object with an existing QFont to obtain metrics for that font. If the font is changed later, the font metrics object is not updated.

Once created, the object provides functions to access the individual metrics of the font, its characters, and for strings rendered in the font.

There are several functions that operate on the font: ascent, descent, height, leading and lineSpacing return the basic size properties of the font. The underlinePos, overlinePos, strikeOutPos and lineWidth functions, return the properties of the line that underlines, overlines or strikes out the characters. These functions are all fast.

There are also some functions that operate on the set of glyphs in the font: minLeftBearing, minRightBearing and maxWidth. These are by necessity slow, and we recommend avoiding them if possible.

For each character, you can get its width, leftBearing and rightBearing and find out whether it is in the font using inFont. You can also treat the character as a string, and use the string functions on it.

The string functions include width, to return the width of a string in pixels (or points, for a printer), boundingRect, to return a rectangle large enough to contain the rendered string, and size(), to return the size of that rectangle.

Example:

    QFont font("times", 24);
    QFontMetricsF fm(font);
    qreal pixelsWide = fm.width("What's the width of this text?");
    qreal pixelsHigh = fm.height();

See also QFont, QFontInfo, and QFontDatabase.


Copyright © 2008 Trolltech Trademarks
Qt Jambi 4.3.5_01