Logo Search packages:      
Sourcecode: qt4-x11 version File versions

QFontMetrics Class Reference

List of all members.


Detailed Description

The QFontMetrics class provides font metrics information.

QFontMetrics functions calculate the size of characters and strings for a given font. There are three ways you can create a QFontMetrics object:

1 Calling the QFontMetrics constructor with a QFont creates a font metrics object for a screen-compatible font, i.e. the font cannot be a printer font. If the font is changed later, the font metrics object is not updated.

(Note: If you use a printer font the values returned may be inaccurate. Printer fonts are not always accessible so the nearest screen font is used if a printer font is supplied.)

QWidget::fontMetrics() returns the font metrics for a widget's font. This is equivalent to QFontMetrics(widget->font()). If the widget's font is changed later, the font metrics object is not updated.

QPainter::fontMetrics() returns the font metrics for a painter's current font. If the painter's 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);
    QFontMetrics fm(font);
    int pixelsWide = fm.width("What's the width of this text?");
    int pixelsHigh = fm.height();

See also:
QFont, QFontInfo, QFontDatabase, QFontComboBox, {Character Map Example}

Definition at line 44 of file qfontmetrics.h.


Public Member Functions

int ascent () const
int averageCharWidth () const
QRect boundingRect (int x, int y, int w, int h, int flags, const QString &text, int tabstops=0, int *tabarray=0) const
QRect boundingRect (const QRect &r, int flags, const QString &text, int tabstops=0, int *tabarray=0) const
QRect boundingRect (const QString &text) const
QRect boundingRect (QChar) const
int charWidth (const QString &str, int pos) const
int descent () const
QString elidedText (const QString &text, Qt::TextElideMode mode, int width, int flags=0) const
int height () const
bool inFont (QChar) const
int leading () const
int leftBearing (QChar) const
int lineSpacing () const
int lineWidth () const
int maxWidth () const
int minLeftBearing () const
int minRightBearing () const
bool operator!= (const QFontMetrics &other) const
bool operator!= (const QFontMetrics &other)
QFontMetricsoperator= (const QFontMetrics &)
bool operator== (const QFontMetrics &other) const
bool operator== (const QFontMetrics &other)
int overlinePos () const
 QFontMetrics (const QFontMetrics &)
 QFontMetrics (const QFont &, QPaintDevice *pd)
 QFontMetrics (const QFont &)
int rightBearing (QChar) const
QSize size (int flags, const QString &str, int tabstops=0, int *tabarray=0) const
int strikeOutPos () const
int underlinePos () const
int width (QChar) const
int width (const QString &, int len=-1) const
int xHeight () const
 ~QFontMetrics ()

Private Attributes

QFontPrivate * d

Friends

class QFontMetricsF
class QStackTextEngine

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index