qfontmetrics.html
来自「QT 下载资料仅供参考」· HTML 代码 · 共 418 行 · 第 1/2 页
HTML
418 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- /home/reggie/tmp/qt-3.0-reggie-5401/qt-x11-commercial-3.0.5/src/kernel/qfont.cpp:1632 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>QFontMetrics Class</title><style type="text/css"><!--h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }a:link { color: #004faf; text-decoration: none }a:visited { color: #672967; text-decoration: none }body { background: #ffffff; color: black; }--></style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr bgcolor="#E5E5E5"><td valign=center> <a href="index.html"><font color="#004faf">Home</font></a> | <a href="classes.html"><font color="#004faf">All Classes</font></a> | <a href="mainclasses.html"><font color="#004faf">Main Classes</font></a> | <a href="annotated.html"><font color="#004faf">Annotated</font></a> | <a href="groups.html"><font color="#004faf">Grouped Classes</font></a> | <a href="functions.html"><font color="#004faf">Functions</font></a></td><td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QFontMetrics Class Reference</h1><p>The QFontMetrics class provides font metrics information.<a href="#details">More...</a><p><tt>#include <<a href="qfontmetrics-h.html">qfontmetrics.h</a>></tt><p><a href="qfontmetrics-members.html">List of all member functions.</a><h2>Public Members</h2><ul><li><div class=fn><a href="#QFontMetrics"><b>QFontMetrics</b></a> ( const QFont & font )</div></li><li><div class=fn><a href="#QFontMetrics-2"><b>QFontMetrics</b></a> ( const QFontMetrics & fm )</div></li><li><div class=fn><a href="#~QFontMetrics"><b>~QFontMetrics</b></a> ()</div></li><li><div class=fn>QFontMetrics & <a href="#operator-eq"><b>operator=</b></a> ( const QFontMetrics & fm )</div></li><li><div class=fn>int <a href="#ascent"><b>ascent</b></a> () const</div></li><li><div class=fn>int <a href="#descent"><b>descent</b></a> () const</div></li><li><div class=fn>int <a href="#height"><b>height</b></a> () const</div></li><li><div class=fn>int <a href="#leading"><b>leading</b></a> () const</div></li><li><div class=fn>int <a href="#lineSpacing"><b>lineSpacing</b></a> () const</div></li><li><div class=fn>int <a href="#minLeftBearing"><b>minLeftBearing</b></a> () const</div></li><li><div class=fn>int <a href="#minRightBearing"><b>minRightBearing</b></a> () const</div></li><li><div class=fn>int <a href="#maxWidth"><b>maxWidth</b></a> () const</div></li><li><div class=fn>bool <a href="#inFont"><b>inFont</b></a> ( QChar ch ) const</div></li><li><div class=fn>int <a href="#leftBearing"><b>leftBearing</b></a> ( QChar ch ) const</div></li><li><div class=fn>int <a href="#rightBearing"><b>rightBearing</b></a> ( QChar ch ) const</div></li><li><div class=fn>int <a href="#width"><b>width</b></a> ( const QString & str, int len = -1 ) const</div></li><li><div class=fn>int <a href="#width-2"><b>width</b></a> ( QChar ch ) const</div></li><li><div class=fn>int width ( char c ) const <em>(obsolete)</em></div></li><li><div class=fn>int <a href="#charWidth"><b>charWidth</b></a> ( const QString & str, int pos ) const</div></li><li><div class=fn>QRect <a href="#boundingRect"><b>boundingRect</b></a> ( const QString & str, int len = -1 ) const</div></li><li><div class=fn>QRect <a href="#boundingRect-2"><b>boundingRect</b></a> ( QChar ch ) const</div></li><li><div class=fn>QRect <a href="#boundingRect-3"><b>boundingRect</b></a> ( 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</div></li><li><div class=fn>QSize <a href="#size"><b>size</b></a> ( int flgs, const QString & str, int len = -1, int tabstops = 0, int * tabarray = 0, QTextParag ** intern = 0 ) const</div></li><li><div class=fn>int <a href="#underlinePos"><b>underlinePos</b></a> () const</div></li><li><div class=fn>int <a href="#strikeOutPos"><b>strikeOutPos</b></a> () const</div></li><li><div class=fn>int <a href="#lineWidth"><b>lineWidth</b></a> () const</div></li></ul><hr><a name="details"></a><h2>Detailed Description</h2>The QFontMetrics class provides font metrics information.<p> <p> QFontMetrics functions calculate the size of characters andstrings for a given font. There are three ways you can create aQFontMetrics object:<p> <ol type=1><li> Calling the QFontMetrics constructor with a <a href="qfont.html">QFont</a> creates afont metrics object for a screen-compatible font, i.e. the fontcannot be a printer font<sup>*</sup>. If the font is changedlater, the font metrics object is <em>not</em> updated.<p> <li> <a href="qwidget.html#fontMetrics">QWidget::fontMetrics</a>() returns the font metrics for a widget'sfont. This is equivalent to QFontMetrics(widget->font()). If thewidget's font is changed later, the font metrics object is <em>not</em>updated.<p> <li> <a href="qpainter.html#fontMetrics">QPainter::fontMetrics</a>() returns the font metrics for apainter's current font. The font metrics object is <em>automatically</em> updated if you set a new painter font.</ol><p> <sup>*</sup> If you use a printer font the values returned willalmost certainly be inaccurate. Printer fonts are not alwaysaccessible so the nearest screen font is used if a printer font issupplied.<p> Once created, the object provides functions to access theindividual metrics of the font, its characters, and for stringsrendered in the font.<p> There are several functions that operate on the font: <a href="#ascent">ascent</a>(),<a href="#descent">descent</a>(), <a href="#height">height</a>(), <a href="#leading">leading</a>() and <a href="#lineSpacing">lineSpacing</a>() return the basicsize properties of the font. The <a href="#underlinePos">underlinePos</a>(), <a href="#strikeOutPos">strikeOutPos</a>()and <a href="#lineWidth">lineWidth</a>() functions, return the properties of the line thatunderlines or strikes out the characters. These functions are allfast.<p> There are also some functions that operate on the set of glyphs inthe font: <a href="#minLeftBearing">minLeftBearing</a>(), <a href="#minRightBearing">minRightBearing</a>() and <a href="#maxWidth">maxWidth</a>().These are by necessity slow, and we recommend avoiding them ifpossible.<p> For each character, you can get its <a href="#width">width</a>(), <a href="#leftBearing">leftBearing</a>() and<a href="#rightBearing">rightBearing</a>() and find out whether it is in the font using<a href="#inFont">inFont</a>(). You can also treat the character as a string, and usethe string functions on it.<p> The string functions include width(), to return the width of astring in pixels (or points, for a printer), <a href="#boundingRect">boundingRect</a>(), toreturn a rectangle large enough to contain the rendered string,and <a href="#size">size</a>(), to return the size of that rectangle.<p> Example:<pre> <a href="qfont.html">QFont</a> font( "times", 24 ); QFontMetrics fm( font ); int pixelsWide = fm.<a href="#width">width</a>( "What's the width of this text?" ); int pixelsHigh = fm.<a href="#height">height</a>(); </pre> <p> <p>See also <a href="qfont.html">QFont</a>, <a href="qfontinfo.html">QFontInfo</a>, <a href="qfontdatabase.html">QFontDatabase</a>, <a href="graphics.html">Graphics Classes</a> and <a href="shared.html">Implicitly and Explicitly Shared Classes</a>.<hr><h2>Member Function Documentation</h2><h3 class=fn><a name="QFontMetrics"></a>QFontMetrics::QFontMetrics ( const <a href="qfont.html">QFont</a> & font )</h3>Constructs a font metrics object for <em>font</em>.<p> The font must be screen-compatible, i.e. a font you use whendrawing text in <a href="qwidget.html">widgets</a> or <a href="qpixmap.html">pixmaps</a>, not <a href="qpicture.html">QPicture</a> or <a href="qprinter.html">QPrinter</a>.<p> The font metrics object holds the information for the font that ispassed in the constructor at the time it is created, and is notupdated if the font's attributes are changed later.<p> Use <a href="qpainter.html#fontMetrics">QPainter::fontMetrics</a>() to get the font metrics when painting.This is a little slower than using this constructor, but it alwaysgives correct results because the font info data is updated.<h3 class=fn><a name="QFontMetrics-2"></a>QFontMetrics::QFontMetrics ( const <a href="qfontmetrics.html">QFontMetrics</a> & fm )</h3>Constructs a copy of <em>fm</em>.<h3 class=fn><a name="~QFontMetrics"></a>QFontMetrics::~QFontMetrics ()</h3>Destroys the font metrics object and frees all allocatedresources.<h3 class=fn>int <a name="ascent"></a>QFontMetrics::ascent () const</h3>Returns the ascent of the font.<p> The ascent of a font is the distance from the baseline to thehighest position characters extend to. In practice, some fontdesigners break this rule, e.g. when they put more than one accenton top of a character, or to accommodate an unusual character inan exotic language, so it is possible (though rare) that thisvalue will be too small.<p> <p>See also <a href="#descent">descent</a>().<p>Examples: <a href="drawdemo-example.html#x1166">drawdemo/drawdemo.cpp</a> and <a href="scrollview-example.html#x706">scrollview/scrollview.cpp</a>.<h3 class=fn><a href="qrect.html">QRect</a> <a name="boundingRect"></a>QFontMetrics::boundingRect ( const <a href="qstring.html">QString</a> & str, int len = -1 ) const</h3>Returns the bounding rectangle of the first <em>len</em> characters of<em>str</em>, which is the set of pixels the text would cover if drawnat (0, 0).<p> If <em>len</em> is negative (the default), the entire string is used.<p> 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 <em>all</em> pixels in the bounding rectangle.<p> Newline characters are processed as normal characters, <em>not</em> aslinebreaks.<p> Due to the different actual character heights, the height of thebounding rectangle of e.g. "Yes" and "yes" may be different.<p> <p>See also <a href="#width">width</a>() and <a href="qpainter.html#boundingRect">QPainter::boundingRect</a>().<p>Example: <a href="xform-example.html#x1424">xform/xform.cpp</a>.<h3 class=fn><a href="qrect.html">QRect</a> <a name="boundingRect-2"></a>QFontMetrics::boundingRect ( <a href="qchar.html">QChar</a> ch ) const</h3>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.<p> Returns the bounding rectangle of the character <em>ch</em> relative tothe left-most point on the base line.<p> 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 <em>all</em> pixels in the bounding rectangle.<p> Note that the rectangle usually extends both above and below thebase line.<p> <p>See also <a href="#width">width</a>().<h3 class=fn><a href="qrect.html">QRect</a> <a name="boundingRect-3"></a>QFontMetrics::boundingRect ( int x, int y, int w, int h, int flgs, const <a href="qstring.html">QString</a> & str, int len = -1, int tabstops = 0, int * tabarray = 0, QTextParag ** intern = 0 ) const</h3>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.<p> Returns the bounding rectangle of the first <em>len</em> characters of<em>str</em>, which is the set of pixels the text would cover if drawnat (0, 0). The drawing, and hence the bounding rectangle, isconstrained to the rectangle (<em>x</em>, <em>y</em>, <em>w</em>, <em>h</em>).<p> If <em>len</em> is negative (which is the default), the entire string isused.<p> The <em>flgs</em> argument is the bitwise OR of the following flags:<ul><li> <tt>AlignAuto</tt> aligns to the left border for all languages exceptArabic and Hebrew where it aligns to the right.<li> <tt>AlignLeft</tt> aligns to the left border.<li> <tt>AlignRight</tt> aligns to the right border.<li> <tt>AlignJustify</tt> produces justified text.<li> <tt>AlignHCenter</tt> aligns horizontally centered.<li> <tt>AlignTop</tt> aligns to the top border.<li> <tt>AlignBottom</tt> aligns to the bottom border.<li> <tt>AlignVCenter</tt> aligns vertically centered<li> <tt>AlignCenter</tt> (== <tt>AlignHCenter | AlignVCenter</tt>)<li> <tt>SingleLine</tt> ignores newline characters in the text.<li> <tt>ExpandTabs</tt> expands tabs (see below)<li> <tt>ShowPrefix</tt> interprets "&x" as "<u>x</u>", i.e. underlined.<li> <tt>WordBreak</tt> breaks the text to fit the rectangle.</ul><p> Horizontal alignment defaults to <tt>AlignAuto</tt> and vertical
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?