📄 qfontmetrics.3qt
字号:
'\" t.TH QFontMetrics 3qt "24 January 2005" "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 about fonts.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:.(lmovies/main.cpp scrollview/scrollview.cpp drawdemo/drawdemo.cpp xform/xform.cpp grapher/grapher.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:.(lscrollview/scrollview.cpp drawdemo/drawdemo.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()..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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -