📄 qfontmetrics.3qt
字号:
'\" t.TH QFontMetrics 3qt "9 December 2002" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2001 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.SH SYNOPSIS\fC#include <qfontmetrics.h>\fR.PP.SS "Public Members".in +1c.ti -1c.BI "\fBQFontMetrics\fR ( const QFont & font )".br.ti -1c.BI "\fBQFontMetrics\fR ( const QFontMetrics & fm )".br.ti -1c.BI "\fB~QFontMetrics\fR ()".br.ti -1c.BI "QFontMetrics & \fBoperator=\fR ( const QFontMetrics & fm )".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 ch ) const".br.ti -1c.BI "int \fBleftBearing\fR ( QChar ch ) const".br.ti -1c.BI "int \fBrightBearing\fR ( QChar ch ) const".br.ti -1c.BI "int \fBwidth\fR ( const QString & str, int len = -1 ) const".br.ti -1c.BI "int \fBwidth\fR ( QChar ch ) const".br.ti -1c.BI "int width ( char c ) const \fI(obsolete)\fR".br.ti -1c.BI "int \fBcharWidth\fR ( const QString & str, int pos ) const".br.ti -1c.BI "QRect \fBboundingRect\fR ( const QString & str, int len = -1 ) const".br.ti -1c.BI "QRect \fBboundingRect\fR ( QChar ch ) const".br.ti -1c.BI "QRect \fBboundingRect\fR ( int x, int y, int w, int h, int flgs, const QString & str, int len = -1, int tabstops = 0, int * tabarray = 0, QTextParag ** intern = 0 ) const".br.ti -1c.BI "QSize \fBsize\fR ( int flgs, const QString & str, int len = -1, int tabstops = 0, int * tabarray = 0, QTextParag ** 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..PPQFontMetrics functions calculate the size of characters and strings for a given font. There are three ways you can create a QFontMetrics object:.PP<ol type=1>.IP 1Calling 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<sup>*</sup>. If the font is changed later, the font metrics object is \fInot\fR updated..IP 2QWidget::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 \fInot\fR updated..IP 3QPainter::fontMetrics() returns the font metrics for a painter's current font. The font metrics object is \fIautomatically\fR updated if you set a new painter font..PP<sup>*</sup> If you use a printer font the values returned will almost certainly be inaccurate. Printer fonts are not always accessible so the nearest screen font is used if a printer font is supplied..PPOnce created, the object provides functions to access the individual metrics of the font, its characters, and for strings rendered in the font..PPThere are several functions that operate on the font: ascent(), descent(), height(), leading() and lineSpacing() return the basic size properties of the font. The underlinePos(), strikeOutPos() and lineWidth() functions, return the 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 a rectangle large enough to contain the rendered string, and size(), to return the size of that rectangle..PPExample:.PP.nf.br QFont font( "times", 24 );.br QFontMetrics fm( font );.br int pixelsWide = fm.width( "What's the width of this text?" );.br int pixelsHigh = fm.height();.br.fi.PPSee also QFont, QFontInfo, QFontDatabase, Graphics Classes, and Implicitly and Explicitly Shared Classes..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 widgets or pixmaps, not QPicture or QPrinter..PPThe font metrics object holds the information for the font that is passed in the constructor at the time it is created, and is not updated if the font's attributes are changed later..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 because the font info data is updated..SH "QFontMetrics::QFontMetrics ( const QFontMetrics & fm )"Constructs a copy of \fIfm\fR..SH "QFontMetrics::~QFontMetrics ()"Destroys the font metrics object and frees all allocated resources..SH "int QFontMetrics::ascent () const"Returns the ascent of the font..PPThe ascent of a font is the distance from the baseline to the highest position characters extend to. In practice, some font designers break this rule, e.g. when they put more than one accent on top of a character, or to accommodate an unusual character in an exotic language, so it is possible (though rare) that this value will be too small..PPSee also descent()..PPExamples:.)l drawdemo/drawdemo.cpp and scrollview/scrollview.cpp..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 (the default), the entire 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 normal 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()..PPExample: xform/xform.cpp..SH "QRect QFontMetrics::boundingRect ( QChar ch ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPReturns the bounding rectangle of the character \fIch\fR relative to the left-most 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()..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, QTextParag ** intern = 0 ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPReturns 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 (\fIx\fR, \fIy\fR, \fIw\fR, \fIh\fR)..PPIf \fIlen\fR is negative (which is the default), the entire string is used..PPThe \fIflgs\fR argument is the bitwise OR of the following flags:.TP\fCAlignAuto\fR aligns to the left border for all languages except Arabic and Hebrew where it aligns to the right..TP\fCAlignLeft\fR aligns to the left border..TP\fCAlignRight\fR aligns to the right border..TP\fCAlignJustify\fR produces justified text..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 | AlignVCenter\fR).TP\fCSingleLine\fR ignores newline characters in the text.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -