📄 qfontmetrics.3qt
字号:
.TH QFontMetrics 3qt "10 November 2000" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2000 Trolltech AS. All rights reserved. See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQFontMetrics \- Font metrics information about fonts.SH SYNOPSIS.br.PP\fC#include <qfontmetrics.h>\fR.PP.SS "Public Members".in +1c.ti -1c.BI "\fBQFontMetrics\fR ( const QFont & ) ".br.ti -1c.BI "\fBQFontMetrics\fR ( const QFontMetrics & ) ".br.ti -1c.BI "\fB~QFontMetrics\fR () ".br.ti -1c.BI "QFontMetrics& \fBoperator=\fR ( const QFontMetrics & ) ".br.ti -1c.BI "int \fBascent\fR () const".br.ti -1c.BI "int \fBdescent\fR () const".br.ti -1c.BI "int \fBheight\fR () const".br.ti -1c.BI "int \fBleading\fR () const".br.ti -1c.BI "int \fBlineSpacing\fR () const".br.ti -1c.BI "int \fBminLeftBearing\fR () const".br.ti -1c.BI "int \fBminRightBearing\fR () const".br.ti -1c.BI "int \fBmaxWidth\fR () const".br.ti -1c.BI "bool \fBinFont\fR ( QChar ) const".br.ti -1c.BI "int \fBleftBearing\fR ( QChar ) const".br.ti -1c.BI "int \fBrightBearing\fR ( QChar ) const".br.ti -1c.BI "int \fBwidth\fR ( const QString &, int " "len" " = -1 ) const".br.ti -1c.BI "int \fBwidth\fR ( QChar ) const".br.ti -1c.BI "int width ( char c ) const \fI(obsolete)\fR".br.ti -1c.BI "QRect \fBboundingRect\fR ( const QString &, int " "len" " = -1 ) const".br.ti -1c.BI "QRect \fBboundingRect\fR ( QChar ) const".br.ti -1c.BI "QRect \fBboundingRect\fR ( int " "x" ", int " "y" ", int " "w" ", int " "h" ", int " "flags" ", const QString & " "str" ", int " "len" "=-1, int " "tabstops" "=0, int * " "tabarray" "=0, char ** " "intern" "=0 ) const".br.ti -1c.BI "QSize \fBsize\fR ( int " "flags" ", const QString & " "str" ", int " "len" "=-1, int " "tabstops" "=0, int * " "tabarray" "=0, char ** " "intern" "=0 ) const".br.ti -1c.BI "int \fBunderlinePos\fR () const".br.ti -1c.BI "int \fBstrikeOutPos\fR () const".br.ti -1c.BI "int \fBlineWidth\fR () const".br.in -1c.SH DESCRIPTIONThe QFontMetrics class provides font metrics information about fonts..PPQFontMetrics functions calculate size of characters and strings for a given font. There are three ways you can create a QFontMetrics object:.PPThe QFontMetrics constructor with a QFont creates a font metrics object for a screen-compatible font, i.e. the font can not be a printer font..PPQWidget::fontMetrics() returns the font metrics for a widget's font. This is equivalent to QFontMetrics(widget->font()). Setting a new font for the widget later does not affect the font metrics object..PPQPainter::fontMetrics() returns the font metrics for a painter's current font. The font metrics object is automatically updated if somebody sets a new painter font (unlike the two above cases, which take a "snapshot" of a font)..PPOnce created, the object provides functions to access the individual metrics of the font, its characters, and for strings rendered in this font..PPThere are several functions that operate on the font: ascent(), descent(), height(), leading() and lineSpacing() return the basic size properties of the font, and underlinePos(), strikeOutPos() and lineWidth() return properties of the line that underlines or strikes out the characters. These functions are all fast..PPThere 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..PPFor 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..PPThe string functions include width(), to return the width of a string in pixels (or points, for a printer), boundingRect(), to return the rectangle necessary to render a string, and size(), to return the size of that rectangle..PPExample:.PP.nf.br QFont font("times",24);.br QFontMetrics fm(font);.br int w = fm.width("What's the width of this text");.br int h = fm.height();.fi.PPSee also QFont and QFontInfo..PPExamples:.(lgrapher/grapher.cpp xform/xform.cpp drawdemo/drawdemo.cpp scrollview/scrollview.cpp movies/main.cpp.)l.SH MEMBER FUNCTION DOCUMENTATION.SH "QFontMetrics::QFontMetrics ( const QFont & font )"Constructs a font metrics object for \fIfont.\fR.PPThe font must be screen-compatible, i.e. a font you use when drawing text in QWidget or QPixmap objects, not QPicture or QPrinter. If \fIfont\fR is a printer font, you'll probably get wrong results..PPUse QPainter::fontMetrics() to get the font metrics when painting. This is a little slower than using this constructor, but it always gives correct results..SH "QFontMetrics::QFontMetrics ( const QFontMetrics & fm )"Constructs a copy of \fIfm.\fR.SH "QFontMetrics::~QFontMetrics ()"Destructs the font metrics object..SH "int QFontMetrics::ascent () const"Returns the maximum ascent of the font..PPThe ascent is the distance from the base line to the uppermost line where pixels may be drawn..PPSee also descent()..PPExamples:.(ldrawdemo/drawdemo.cpp scrollview/scrollview.cpp.)l.SH "QRect QFontMetrics::boundingRect ( QChar ch ) const"Returns the bounding rectangle of \fIch\fR relative to the leftmost point on the base line..PPNote that the bounding rectangle may extend to the left of (0,0), e.g. for italicized fonts, and that the text output may cover \fIall\fR pixels in the bounding rectangle..PPNote that the rectangle usually extends both above and below the base line..PPSee also width()..PPExamples:.(lxform/xform.cpp.)l.SH "QRect QFontMetrics::boundingRect ( const QString & str, int len = -1 ) const"Returns the bounding rectangle of the first \fIlen\fR characters of \fIstr,\fR which is the set of pixels the text would cover if drawn at (0,0)..PPIf \fIlen\fR is negative (default value), the whole string is used..PPNote that the bounding rectangle may extend to the left of (0,0), e.g. for italicized fonts, and that the text output may cover \fIall\fR pixels in the bounding rectangle..PPNewline characters are processed as regular characters, \fInot\fR as linebreaks..PPDue to the different actual character heights, the height of the bounding rectangle of e.g. "Yes" and "yes" may be different..PPSee also width() and QPainter::boundingRect()..SH "QRect QFontMetrics::boundingRect ( int x, int y, int w, int h, int flgs, const QString & str, int len=-1, int tabstops=0, int * tabarray=0, char ** intern=0 ) const"Returns the bounding rectangle of the first \fIlen\fR characters of \fIstr,\fR which is the set of pixels the text would cover if drawn at (0,0). The drawing, and hence the bounding rectangle, is constrained to the rectangle \fI(x,y,w,h).\fR.PPIf \fIlen\fR is negative (default value), the whole string is used..PPThe \fIflgs\fR argument is the bitwise OR of the following flags: .TP\fCAlignLeft\fR aligns to the left border..TP\fCAlignRight\fR aligns to the right border..TP\fCAlignHCenter\fR aligns horizontally centered..TP\fCAlignTop\fR aligns to the top border..TP\fCAlignBottom\fR aligns to the bottom border..TP\fCAlignVCenter\fR aligns vertically centered.TP\fCAlignCenter\fR (= \fCAlignHCenter\fR | AlignVCenter).TP\fCSingleLine\fR ignores newline characters in the text..TP\fCExpandTabs\fR expands tabulators..TP\fCShowPrefix\fR interprets "&x" as "x" underlined..TP\fCWordBreak\fR breaks the text to fit the rectangle..PPHorizontal alignment defaults to AlignLeft and vertical alignment defaults to AlignTop..PPIf several of the horizontal or several of the vertical alignment flags are set, the resulting alignment is undefined..PPThese flags are defined in qnamespace.h..PPIf \fCExpandTabs\fR is set in \fIflgs,\fR then: if \fItabarray\fR is non.zero, it specifies a 0-terminated sequence of pixel-positions for tabs; otherwise if \fItabstops\fR is non-zero, it is used as the tab spacing (in pixels)..PPNote that the bounding rectangle may extend to the left of (0,0), e.g. for italicized fonts, and that the text output may cover \fIall\fR pixels in the bounding rectangle..PPNewline characters are processed as linebreaks..PPDespite the different actual character heights, the heights of the bounding rectangles of "Yes" and "yes" are the same..PPThe 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..PPThe \fIinternal\fR argument is for internal purposes..PPSee also width(), QPainter::boundingRect() and Qt::AlignmentFlags..SH "int QFontMetrics::descent () const"Returns the maximum descent of the font..PPThe 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.).PPSee also ascent()..PPExamples:.(ldrawdemo/drawdemo.cpp.)l.SH "int QFontMetrics::height () const"Returns the height of the font..PPThis is always equal to ascent()+descent()+1 (the 1 is for the base line)..PPSee also leading() and lineSpacing()..PPExamples:.(lgrapher/grapher.cpp.)l.SH "bool QFontMetrics::inFont ( QChar ch ) const"Returns TRUE if \fIch\fR is a valid character in the font..SH "int QFontMetrics::leading () const"Returns the leading of the font..PPThis is the natural inter-line spacing..PPSee also height() and lineSpacing()..SH "int QFontMetrics::leftBearing ( QChar ch ) const"Returns the left bearing of character \fIch\fR in the font..PPThe 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..PPSee width(QChar) for a graphical description of this metric..PPSee also rightBearing(QChar), minLeftBearing() and width()..SH "int QFontMetrics::lineSpacing () const"Returns the distance from one base line to the next..PPThis value is always equal to leading()+height()..PPSee also height() and leading()..PPExamples:.(lscrollview/scrollview.cpp.)l.SH "int QFontMetrics::lineWidth () const"Returns the width of the underline and strike-out lines, adjusted for the point size of the font..PPSee also underlinePos() and strikeOutPos()..SH "int QFontMetrics::maxWidth () const"Returns the width of the widest character in the font..SH "int QFontMetrics::minLeftBearing () const"Returns the minimum left bearing of the font..PPThis is the smallest leftBearing(char) of all characters in the font..PPNote that this function can be very slow if the font is big..PPSee also minRightBearing() and leftBearing(char)..SH "int QFontMetrics::minRightBearing () const"Returns the minimum right bearing of the font..PPThis is the smallest rightBearing(char) of all characters in the font..PPNote that this function can be very slow if the font is big..PPSee also minLeftBearing() and rightBearing(char)..SH "QFontMetrics & QFontMetrics::operator= ( const QFontMetrics & fm )"Font metrics assignment..SH "int QFontMetrics::rightBearing ( QChar ch ) const"Returns the right bearing of character \fIch\fR in the font..PPThe 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..PPSee width() for a graphical description of this metric..PPSee also leftBearing(char), minRightBearing() and width()..SH "QSize QFontMetrics::size ( int flgs, const QString & str, int len=-1, int tabstops=0, int * tabarray=0, char ** intern=0 ) const"Returns the size in pixels of the first \fIlen\fR characters of \fIstr.\fR.PPIf \fIlen\fR is negative (default value), the whole string is used..PPThe \fIflgs\fR argument is the bitwise OR of the following flags: .TP\fCSingleLine\fR ignores newline characters in the text..TP\fCExpandTabs\fR expands tabulators..TP\fCShowPrefix\fR interprets "&x" as "x" underlined..TP\fCWordBreak\fR breaks the text to fit the rectangle..PPThese flags are defined in qnamespace.h..PPIf \fCExpandTabs\fR is set in \fIflgs,\fR then: if \fItabarray\fR is non.zero, it specifies a 0-terminated sequence of pixel-positions for tabs; otherwise if \fItabstops\fR is non-zero, it is used as the tab spacing (in pixels)..PPNewline characters are processed as linebreaks..PPDespite the different actual character heights, the heights of the bounding rectangles of "Yes" and "yes" are the same..PPThe \fIinternal\fR argument is for internal purposes..PPSee also boundingRect()..SH "int QFontMetrics::strikeOutPos () const"Returns the distance from the base line to where the strike-out line should be drawn..PPSee also underlinePos() and lineWidth()..SH "int QFontMetrics::underlinePos () const"Returns the distance from the base line to where an underscore should be drawn..PPSee also strikeOutPos() and lineWidth()..SH "int QFontMetrics::width ( QChar ch ) const"<img src="bearings.png" align=right> Returns the logical width of a \fIch\fR in pixels. This is a distance appropriate for drawing a subsequent character after \fIch.\fR.PPSome 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 leftBearing() and rightBearing() of the characters. Notice that the bearings of "f" in this particular font are both negative, while the bearings of "o" are both positive..PPSee also boundingRect()..SH "int QFontMetrics::width ( const QString & str, int len = -1 ) const"Returns the width in pixels of the first \fIlen\fR characters of \fIstr.\fR.PPIf \fIlen\fR is negative (the default value is), the whole string is used..PPNote that this value is \fInot\fR 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..PPSee also boundingRect()..PPExamples:.(ldrawdemo/drawdemo.cpp scrollview/scrollview.cpp movies/main.cpp.)l.SH "int QFontMetrics::width ( char c ) const"\fBThis function is obsolete.\fR It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code..PPThis is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PPProvided to aid porting from Qt 1.x..SH "SEE ALSO".BR http://doc.trolltech.com/qfontmetrics.html.SH COPYRIGHTCopyright 1992-2000 Trolltech AS, http://www.trolltech.com/. See thelicense file included in the distribution for a complete licensestatement..SH AUTHORGenerated automatically from the source code.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -