The QFontMetrics class provides font metrics information about fonts. More...
#include <qfontmet.h>
QFontMetrics functions calculate size of characters and strings for a given font.
There are three ways you can create a QFontMetrics object:
Example:
QFont font("times",24); QFontMetrics fm(font); int w = fm.width("What's the width of this text"); int h = fm.height();
In Qt 2.0 the font metrics object will no longer be automatically updated when the widget or painter gets a new font. Make sure you program does not depend on this feature.
About efficiency: We recommend that you use the QFontMetrics constructor if you can. This is more efficient than getting the font metrics from a widget or a painter. The QWidget::fontMetrics() and QPainter::fontMetrics() will become faster in Qt 2.0, when we have removed the automatic update policy.
See also: QFont and QFontInfo.
Examples: drawdemo/drawdemo.cpp xform/xform.cpp hello/hello.cpp movies/main.cpp
Constructs a font metrics object for font.
The font must be screen-compatible, i.e. a font you use when drawing text in widgets or pixmaps. If font is a printer font, you'll probably get wrong results.
Use the QPainter::fontMetrics() to get the font metrics when painting. This is a little slower than using this constructor, but it always gives correct results.
Constructs a copy of fm.
Destroys the font metrics object.
Returns the maximum ascent of the font.
The ascent is the distance from the base line to the uppermost line where pixels may be drawn.
See also: descent().
Examples: drawdemo/drawdemo.cpp
Returns the bounding rectangle of ch relative to the leftmost point on the base line.
Note that the bounding rectangle may extend to the left of (0,0), e.g. for italicized fonts, and that the text output may cover all pixels in the bounding rectangle.
Note that the rectangle usually extends both above and below the base line.
See also: width().
Returns the bounding rectangle of the first len characters of str.
If len is negative (default value), the whole string is used.
Note that the bounding rectangle may extend to the left of (0,0), e.g. for italicized fonts, and that the text output may cover all pixels in the bounding rectangle.
See also: width().
Examples: xform/xform.cpp
Returns the maximum descent of the font.
The descent is the distance from the base line to the lowermost line where pixels may be drawn. (Note that this is different from X, which adds 1 pixel.)
See also: ascent().
Examples: drawdemo/drawdemo.cpp hello/hello.cpp
Returns the height of the font.
This is always equal to ascent()+descent()+1 (the 1 is for the base line).
See also: leading() and lineSpacing().
Examples: hello/hello.cpp
Returns the leading of the font.
This is the natural inter-line spacing.
See also: height() and lineSpacing().
Returns the distance from one base line to the next.
This value is always equal to leading()+height().
See also: height() and leading().
Returns the width of the underline and strike-out lines, adjusted for the point size of the font.
See also: underlinePos() and strikeOutPos().
Returns the width of the widest character in the font.
Font metrics assignment.
Returns the distance from the base line to where the strike-out line should be drawn.
See also: underlinePos() and lineWidth().
Returns the distance from the base line to where an underscore should be drawn.
See also: strikeOutPos() and lineWidth().
Returns the pixel width of a ch.
See also: boundingRect().
Returns the width in pixels of the first len characters of str.
If len is negative (default value), the whole string is used.
Note that this value is not equal to boundingRect().width(); boundingRect() returns a rectangle describing the pixels this string will cover whereas width() returns the distance to where the next string should be drawn. Thus, width(stra)+width(strb) is always equal to width(strcat(stra, strb)). This is almost never the case with boundingRect().
See also: boundingRect().
Examples: drawdemo/drawdemo.cpp hello/hello.cpp movies/main.cpp
This file is part of the Qt toolkit, copyright © 1995-97 Troll Tech, all rights reserved.
It was generated from the following files: