QFontMetrics Class Reference


The QFontMetrics class provides font metrics information about the current font for a widget or a painter. More...

#include <qfontmet.h>

List of all member functions.

Public Members


Detailed Description

The QFontMetrics class provides font metrics information about the current font for a widget or a painter.

QFontMetrics functions calculate size of characters and strings for a given font.

Notice that the constructors are private and you can only get a font metrics object by calling QWidget::fontMetrics() or QPainter::fontMetrics().

A font metrics object will always refer to the font currently set for the widget or painter that the font metrics object was obtained from. Changing a widget font will update all QFontMetrics objects that refer to this widget.

See also: QFont and QFontInfo.

Examples: drawdemo/drawdemo.cpp showimg/showimg.cpp


Member Function Documentation

QFontMetrics::QFontMetrics ( const QFontMetrics &fm)

Constructs a copy of fm.

QFontMetrics::~QFontMetrics ()

Destroys the font metrics object.

int QFontMetrics::ascent () const

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 showimg/showimg.cpp

QRect QFontMetrics::boundingRect ( char ch) const

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().

QRect QFontMetrics::boundingRect ( const char *str, int len = -1) const

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) and that the text output may cover all pixels in the bounding rectangle.

See also: width().

int QFontMetrics::descent () const

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

const QFont & QFontMetrics::font () const

Returns the font currently set for the widget or painter.

int QFontMetrics::height () const

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: showimg/showimg.cpp

int QFontMetrics::leading () const

Returns the leading of the font.

This is the natural inter-line spacing.

See also: height() and lineSpacing().

int QFontMetrics::lineSpacing () const

Returns the distance from one base line to the next.

This value is always equal to leading()+height().

See also: height() and leading().

int QFontMetrics::lineWidth () const

Returns the width of the underline and strike-out lines, adjusted for the point size of the font.

See also: underlinePos() and strikeOutPos().

int QFontMetrics::maxWidth () const

Returns the width of the widest character in the font.

QFontMetrics & QFontMetrics::operator= ( const QFontMetrics &fm)

Font metrics assignment.

int QFontMetrics::strikeOutPos () const

Returns the distance from the base line to where the strike-out line should be drawn.

See also: underlinePos() and lineWidth().

int QFontMetrics::underlinePos () const

Returns the distance from the base line to where an underscore should be drawn.

See also: strikeOutPos() and lineWidth().

int QFontMetrics::width ( char ch) const

Returns the pixel width of a ch.

See also: boundingRect().

Examples: drawdemo/drawdemo.cpp showimg/showimg.cpp

int QFontMetrics::width ( const char *str, int len = -1) const

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().


This file is part of the Qt toolkit, copyright © 1995-96 Troll Tech, all rights reserved.

It was generated from the following files:


Generated at 16:51, 1996/09/24 for Qt version 1.0 by the webmaster at Troll Tech