The QFontMetrics class provides font metrics information about fonts. More...
#include <qfontmetrics.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();
NOTE: 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: grapher/grapher.cpp drawdemo/drawdemo.cpp hello/hello.cpp movies/main.cpp xform/xform.cpp application/application.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, which is the set of pixels the text would cover if drawn at (0,0).
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.
Newline characters are processed as regular characters, not as linebreaks.
Due to the different actual character heights, the height of the bounding rectangle of "Yes" and "yes" may be different.
See also: width() and QPainter::boundingRect().
Examples: xform/xform.cpp
Returns the bounding rectangle of the first len characters of str, which is the set of pixels the text would cover if drawn at (0,0).
If len is negative (default value), the whole string is used.
The flags argument is the bitwise OR of the following flags:
AlignLeft
aligns to the left border.
AlignRight
aligns to the right border.
AlignHCenter
aligns horizontally centered.
AlignTop
aligns to the top border.
AlignBottom
aligns to the bottom border.
AlignVCenter
aligns vertically centered
AlignCenter
(= AlignHCenter
| AlignVCenter)
SingleLine
ignores newline characters in the text.
ExpandTabs
expands tabulators.
ShowPrefix
interprets "&x" as "x" underlined.
WordBreak
breaks the text to fit the rectangle.
Horizontal alignment defaults to AlignLeft and vertical alignment defaults to AlignTop.
If several of the horizontal or several of the vertical alignment flags are set, the resulting alignment is undefined.
These flags are defined in qwindowdefs.h.
If ExpandTabs
is set in flags, then:
if tabarray is non.zero, it specifies a 0-terminated sequence
of pixel-positions for tabs; otherwise
if tabstops is non-zero, it is used as the tab spacing (in pixels).
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.
Newline characters are processed as linebreaks.
Despite the different actual character heights, the heights of the bounding rectangles of "Yes" and "yes" are the same.
The bounding rectangle given by this function is somewhat larger than that calculated by the simpler boundingRect() function. This function uses the maximum left and right font bearings as is necessary for multi-line text to align correctly. Also, fontHeight() and lineSpacing() are used to calculate the height, rather than individual character heights.
The internal argument is for internal purposes.
See also: width() and QPainter::boundingRect().
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: grapher/grapher.cpp hello/hello.cpp
Returns TRUE if ch is a valid character in the font.
Returns the leading of the font.
This is the natural inter-line spacing.
See also: height() and lineSpacing().
Returns the left bearing of character ch in the font.
The left bearing is the rightward distance of the left-most pixel of the character from the logical origin of the character. This value is negative if the pixels of the character extend to the left of the logical origin.
See width(char) for a graphical description of this metric.
See also: rightBearing(char), minLeftBearing() and width().
Returns the distance from one base line to the next.
This value is always equal to leading()+height().
See also: height() and leading().
Examples: application/application.cpp
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.
Returns the minimum left bearing of the font.
This is the smallest leftBearing(char) of all characters in the font.
See also: minRightBearing() and leftBearing(char).
Returns the minimum right bearing of the font.
This is the smallest rightBearing(char) of all characters in the font.
See also: minLeftBearing() and rightBearing(char).
Font metrics assignment.
Returns the right bearing of character ch in the font.
The right bearing is the leftward distance of the right-most pixel of the character from the logical origin of a subsequent character. This value is negative if the pixels of the character extend to the right of the width() of the character.
See width() for a graphical description of this metric.
See also: leftBearing(char), minRightBearing() and width().
Returns the size in pixels of the first len characters of str.
If len is negative (default value), the whole string is used.
The flags argument is the bitwise OR of the following flags:
SingleLine
ignores newline characters in the text.
ExpandTabs
expands tabulators.
ShowPrefix
interprets "&x" as "x" underlined.
WordBreak
breaks the text to fit the rectangle.
These flags are defined in qwindowdefs.h.
If ExpandTabs
is set in flags, then:
if tabarray is non.zero, it specifies a 0-terminated sequence
of pixel-positions for tabs; otherwise
if tabstops is non-zero, it is used as the tab spacing (in pixels).
Newline characters are processed as linebreaks.
Despite the different actual character heights, the heights of the bounding rectangles of "Yes" and "yes" are the same.
The internal argument is for internal purposes.
See also: boundingRect().
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 logical width of a ch in pixels. This is a distance appropriate for drawing a subsequent character after ch.
Some of the metrics are described in the image to the right. The tall dark rectangle covers the logical width() of a character. The shorter pale rectangles cover the left and right bearings of the characters. Notice that the bearings of "f" in this particular font are both negative, while the bearings of "o" are both positive.
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
Search the documentation, FAQ, qt-interest archive and more (uses
www.troll.no):
This file is part of the Qt toolkit, copyright © 1995-98 Troll Tech, all rights reserved.
It was generated from the following files:
Copyright İ 1998 Troll Tech | Trademarks | Qt version 1.42
|