<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html><head><title>QFontMetrics Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm } a:link { color: #004faf; text-decoration: none } a:visited { color: #672967; text-decoration: none } td.postheader { font-family: sans-serif } tr.address { font-family: sans-serif } body { background: #ffffff; color: black; } </style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">  </td><td class="postheader" 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="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QFontMetrics Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QFontMetrics class provides font metrics information. <a href="#details">More...</a></p> <h3>Methods</h3><ul><li><div class="fn" /><b><a href="qfontmetrics.html#QFontMetrics">__init__</a></b> (<i>self</i>, QFont)</li><li><div class="fn" /><b><a href="qfontmetrics.html#QFontMetrics-2">__init__</a></b> (<i>self</i>, QFont, QPaintDevice <i>pd</i>)</li><li><div class="fn" /><b><a href="qfontmetrics.html#QFontMetrics-3">__init__</a></b> (<i>self</i>, QFontMetrics)</li><li><div class="fn" />int <b><a href="qfontmetrics.html#ascent">ascent</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qfontmetrics.html#averageCharWidth">averageCharWidth</a></b> (<i>self</i>)</li><li><div class="fn" />QRect <b><a href="qfontmetrics.html#boundingRect">boundingRect</a></b> (<i>self</i>, QChar)</li><li><div class="fn" />QRect <b><a href="qfontmetrics.html#boundingRect-2">boundingRect</a></b> (<i>self</i>, QString <i>text</i>)</li><li><div class="fn" />QRect <b><a href="qfontmetrics.html#boundingRect-3">boundingRect</a></b> (<i>self</i>, QRect <i>rect</i>, int <i>flags</i>, QString <i>text</i>, int <i>tabStops</i> = 0, list-of-int <i>tabArray</i> = 0)</li><li><div class="fn" />QRect <b><a href="qfontmetrics.html#boundingRect-4">boundingRect</a></b> (<i>self</i>, int <i>x</i>, int <i>y</i>, int <i>width</i>, int <i>height</i>, int <i>flags</i>, QString <i>text</i>, int <i>tabStops</i> = 0, list-of-int <i>tabArray</i> = 0)</li><li><div class="fn" />QRect <b><a href="qfontmetrics.html#boundingRectChar">boundingRectChar</a></b> (<i>self</i>, QChar)</li><li><div class="fn" />int <b><a href="qfontmetrics.html#charWidth">charWidth</a></b> (<i>self</i>, QString <i>str</i>, int <i>pos</i>)</li><li><div class="fn" />int <b><a href="qfontmetrics.html#descent">descent</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qfontmetrics.html#elidedText">elidedText</a></b> (<i>self</i>, QString <i>text</i>, Qt.TextElideMode <i>mode</i>, int <i>width</i>, int <i>flags</i> = 0)</li><li><div class="fn" />int <b><a href="qfontmetrics.html#height">height</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qfontmetrics.html#inFont">inFont</a></b> (<i>self</i>, QChar)</li><li><div class="fn" />bool <b><a href="qfontmetrics.html#inFontUcs4">inFontUcs4</a></b> (<i>self</i>, int <i>character</i>)</li><li><div class="fn" />int <b><a href="qfontmetrics.html#leading">leading</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qfontmetrics.html#leftBearing">leftBearing</a></b> (<i>self</i>, QChar)</li><li><div class="fn" />int <b><a href="qfontmetrics.html#lineSpacing">lineSpacing</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qfontmetrics.html#lineWidth">lineWidth</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qfontmetrics.html#maxWidth">maxWidth</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qfontmetrics.html#minLeftBearing">minLeftBearing</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qfontmetrics.html#minRightBearing">minRightBearing</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qfontmetrics.html#overlinePos">overlinePos</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qfontmetrics.html#rightBearing">rightBearing</a></b> (<i>self</i>, QChar)</li><li><div class="fn" />QSize <b><a href="qfontmetrics.html#size">size</a></b> (<i>self</i>, int <i>flags</i>, QString <i>text</i>, int <i>tabStops</i> = 0, list-of-int <i>tabArray</i> = 0)</li><li><div class="fn" />int <b><a href="qfontmetrics.html#strikeOutPos">strikeOutPos</a></b> (<i>self</i>)</li><li><div class="fn" />QRect <b><a href="qfontmetrics.html#tightBoundingRect">tightBoundingRect</a></b> (<i>self</i>, QString <i>text</i>)</li><li><div class="fn" />int <b><a href="qfontmetrics.html#underlinePos">underlinePos</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qfontmetrics.html#width">width</a></b> (<i>self</i>, QChar)</li><li><div class="fn" />int <b><a href="qfontmetrics.html#width-2">width</a></b> (<i>self</i>, QString <i>text</i>, int <i>length</i> = -1)</li><li><div class="fn" />int <b><a href="qfontmetrics.html#widthChar">widthChar</a></b> (<i>self</i>, QChar)</li><li><div class="fn" />int <b><a href="qfontmetrics.html#xHeight">xHeight</a></b> (<i>self</i>)</li></ul><h3>Special Methods</h3><ul><li><div class="fn" />bool <b><a href="qfontmetrics.html#__eq__">__eq__</a></b> (<i>self</i>, QFontMetrics <i>other</i>)</li><li><div class="fn" />bool <b><a href="qfontmetrics.html#__ne__">__ne__</a></b> (<i>self</i>, QFontMetrics <i>other</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QFontMetrics class provides font metrics information.</p> <p>QFontMetrics functions calculate the size of characters and strings for a given font. There are three ways you can create a QFontMetrics object:</p> <ol class="1"> <li>Calling the QFontMetrics constructor with a <a href="qfont.html">QFont</a> 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 <i>not</i> updated. <p>(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.)</p> </li> <li><a href="qwidget.html#fontMetrics">QWidget.fontMetrics</a>() 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 <i>not</i> updated.</li> <li><a href="qpainter.html#fontMetrics">QPainter.fontMetrics</a>() returns the font metrics for a painter's current font. If the painter's font is changed later, the font metrics object is <i>not</i> updated.</li> </ol> <p>Once created, the object provides functions to access the individual metrics of the font, its characters, and for strings rendered in the font.</p> <p>There are several functions that operate on the font: <a href="qfontmetrics.html#ascent">ascent</a>(), <a href="qfontmetrics.html#descent">descent</a>(), <a href="qfontmetrics.html#height">height</a>(), <a href="qfontmetrics.html#leading">leading</a>() and <a href="qfontmetrics.html#lineSpacing">lineSpacing</a>() return the basic size properties of the font. The <a href="qfontmetrics.html#underlinePos">underlinePos</a>(), <a href="qfontmetrics.html#overlinePos">overlinePos</a>(), <a href="qfontmetrics.html#strikeOutPos">strikeOutPos</a>() and <a href="qfontmetrics.html#lineWidth">lineWidth</a>() functions, return the properties of the line that underlines, overlines or strikes out the characters. These functions are all fast.</p> <p>There are also some functions that operate on the set of glyphs in the font: <a href="qfontmetrics.html#minLeftBearing">minLeftBearing</a>(), <a href="qfontmetrics.html#minRightBearing">minRightBearing</a>() and <a href="qfontmetrics.html#maxWidth">maxWidth</a>(). These are by necessity slow, and we recommend avoiding them if possible.</p> <p>For each character, you can get its <a href="qfontmetrics.html#width">width</a>(), <a href="qfontmetrics.html#leftBearing">leftBearing</a>() and <a href="qfontmetrics.html#rightBearing">rightBearing</a>() and find out whether it is in the font using <a href="qfontmetrics.html#inFont">inFont</a>(). You can also treat the character as a string, and use the string functions on it.</p> <p>The string functions include <a href="qfontmetrics.html#width">width</a>(), to return the width of a string in pixels (or points, for a printer), <a href="qfontmetrics.html#boundingRect">boundingRect</a>(), to return a rectangle large enough to contain the rendered string, and <a href="qfontmetrics.html#size">size</a>(), to return the size of that rectangle.</p> <p>Example:</p> <pre class="cpp"> <span class="type"><a href="qfont.html">QFont</a></span> font(<span class="string">"times"</span><span class="operator">,</span> <span class="number">24</span>); <span class="type">QFontMetrics</span> fm(font); <span class="type">int</span> pixelsWide <span class="operator">=</span> fm<span class="operator">.</span><a href="qfontmetrics.html#width">width</a>(<span class="string">"What's the width of this text?"</span>); <span class="type">int</span> pixelsHigh <span class="operator">=</span> fm<span class="operator">.</span><a href="qfontmetrics.html#height">height</a>(); </pre><hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QFontMetrics" />QFontMetrics.__init__ (<i>self</i>, <a href="qfont.html">QFont</a>)</h3><p>Constructs a font metrics object for <i>font</i>.</p> <p>The font metrics will be compatible with the paintdevice used to create <i>font</i>.</p> <p>The 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.</p> <p>Use <a href="qfontmetrics.html">QFontMetrics</a>(const <a href="qfont.html">QFont</a> &, <a href="qpaintdevice.html">QPaintDevice</a> *) to get the font metrics that are compatible with a certain paint device.</p> <h3 class="fn"><a name="QFontMetrics-2" />QFontMetrics.__init__ (<i>self</i>, <a href="qfont.html">QFont</a>, <a href="qpaintdevice.html">QPaintDevice</a> <i>pd</i>)</h3><p>Constructs a font metrics object for <i>font</i> and <i>paintdevice</i>.</p> <p>The font metrics will be compatible with the paintdevice passed. If the <i>paintdevice</i> is 0, the metrics will be screen-compatible, ie. the metrics you get if you use the font for drawing text on a <a href="qwidget.html">widgets</a> or <a href="qpixmap.html">pixmaps</a>, not on a <a href="qpicture.html">QPicture</a> or <a href="qprinter.html">QPrinter</a>.</p> <p>The 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.</p> <h3 class="fn"><a name="QFontMetrics-3" />QFontMetrics.__init__ (<i>self</i>, <a href="qfontmetrics.html">QFontMetrics</a>)</h3><p>Constructs a copy of <i>fm</i>.</p> <h3 class="fn"><a name="ascent" />int QFontMetrics.ascent (<i>self</i>)</h3><p>Returns the ascent of the font.</p> <p>The 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.</p> <p><b>See also</b> <a href="qfontmetrics.html#descent">descent</a>().</p> <h3 class="fn"><a name="averageCharWidth" />int QFontMetrics.averageCharWidth (<i>self</i>)</h3><p>Returns the average width of glyphs in the font.</p> <p>This function was introduced in Qt 4.2.</p> <h3 class="fn"><a name="boundingRect" /><a href="qrect.html">QRect</a> QFontMetrics.boundingRect (<i>self</i>, QChar)</h3><p>Returns the rectangle that is covered by ink if character <i>ch</i> were to be drawn at the origin of the coordinate system.</p> <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 <i>all</i> pixels in the bounding rectangle. For a space character the rectangle will usually be empty.</p> <p>Note that the rectangle usually extends both above and below the base line.</p> <p><b>Warning:</b> The width of the returned rectangle is not the advance width of the character. Use boundingRect(const <a href="qstring.html">QString</a> &) or <a href="qfontmetrics.html#width">width</a>() instead.</p> <p><b>See also</b> <a href="qfontmetrics.html#width">width</a>().</p> <h3 class="fn"><a name="boundingRect-2" /><a href="qrect.html">QRect</a> QFontMetrics.boundingRect (<i>self</i>, QString <i>text</i>)</h3><p>Returns the bounding rectangle of the characters in the string specified by <i>text</i>. The bounding rectangle always covers at least the set of pixels the text would cover if drawn at (0, 0).</p> <p>Note that the bounding rectangle may extend to the left of (0, 0), e.g. for italicized fonts, and that the width of the returned rectangle might be different than what the <a href="qfontmetrics.html#width">width</a>() method returns.</p> <p>If you want to know the advance width of the string (to layout a set of strings next to each other), use <a href="qfontmetrics.html#width">width</a>() instead.</p> <p>Newline characters are processed as normal characters, <i>not</i> as linebreaks.</p> <p>The height of the bounding rectangle is at least as large as the value returned by <a href="qfontmetrics.html#height">height</a>().</p> <p><b>See also</b> <a href="qfontmetrics.html#width">width</a>(), <a href="qfontmetrics.html#height">height</a>(), <a href="qpainter.html#boundingRect">QPainter.boundingRect</a>(), and <a href="qfontmetrics.html#tightBoundingRect">tightBoundingRect</a>().</p> <h3 class="fn"><a name="boundingRect-3" /><a href="qrect.html">QRect</a> QFontMetrics.boundingRect (<i>self</i>, <a href="qrect.html">QRect</a> <i>rect</i>, int <i>flags</i>, QString <i>text</i>, int <i>tabStops</i> = 0, list-of-int <i>tabArray</i> = 0)</h3><p>The <i>tabArray</i> argument may also be None.</p><h3 class="fn"><a name="boundingRect-4" /><a href="qrect.html">QRect</a> QFontMetrics.boundingRect (<i>self</i>, int <i>x</i>, int <i>y</i>, int <i>width</i>, int <i>height</i>, int <i>flags</i>, QString <i>text</i>, int <i>tabStops</i> = 0, list-of-int <i>tabArray</i> = 0)</h3><p>The <i>tabArray</i> argument may also be None.</p><h3 class="fn"><a name="boundingRectChar" /><a href="qrect.html">QRect</a> QFontMetrics.boundingRectChar (<i>self</i>, QChar)</h3><h3 class="fn"><a name="charWidth" />int QFontMetrics.charWidth (<i>self</i>, QString <i>str</i>, int <i>pos</i>)</h3><h3 class="fn"><a name="descent" />int QFontMetrics.descent (<i>self</i>)</h3><p>Returns the descent of the font.</p> <p>The descent is the distance from the base line to the lowest point characters extend to. In practice, some font designers break this rule, e.g. to accommodate an unusual character in an exotic language, so it is possible (though rare) that this value will be too small.</p> <p><b>See also</b> <a href="qfontmetrics.html#ascent">ascent</a>().</p> <h3 class="fn"><a name="elidedText" />QString QFontMetrics.elidedText (<i>self</i>, QString <i>text</i>, <a href="qt.html#TextElideMode-enum">Qt.TextElideMode</a> <i>mode</i>, int <i>width</i>, int <i>flags</i> = 0)</h3><p>If the string <i>text</i> is wider than <i>width</i>, returns an elided version of the string (i.e., a string with "..." in it). Otherwise, returns the original string.</p> <p>The <i>mode</i> parameter specifies whether the text is elided on the left (e.g., "...tech"), in the middle (e.g., "Tr...ch"), or on the right (e.g., "Trol...").</p> <p>The <i>width</i> is specified in pixels, not characters.</p> <p>The <i>flags</i> argument is optional and currently only supports <a href="qt.html#TextFlag-enum">Qt.TextShowMnemonic</a> as value.</p> <p>The elide mark will follow the <a href="qt.html#LayoutDirection-enum">layout direction</a>; it will be on the right side of the text for right-to-left layouts, and on the left side for right-to-left layouts. Note that this behavior is independent of the text language.</p> <p>This function was introduced in Qt 4.2.</p> <h3 class="fn"><a name="height" />int QFontMetrics.height (<i>self</i>)</h3><p>Returns the height of the font.</p> <p>This is always equal to <a href="qfontmetrics.html#ascent">ascent</a>()+<a href="qfontmetrics.html#descent">descent</a>()+1 (the 1 is for the base line).</p> <p><b>See also</b> <a href="qfontmetrics.html#leading">leading</a>() and <a href="qfontmetrics.html#lineSpacing">lineSpacing</a>().</p> <h3 class="fn"><a name="inFont" />bool QFontMetrics.inFont (<i>self</i>, QChar)</h3><p>Returns true if character <i>ch</i> is a valid character in the font; otherwise returns false.</p> <h3 class="fn"><a name="inFontUcs4" />bool QFontMetrics.inFontUcs4 (<i>self</i>, int <i>character</i>)</h3><p>Returns true if the given <i>character</i> encoded in UCS-4/UTF-32 is a valid character in the font; otherwise returns false.</p> <p>This function was introduced in Qt 4.8.</p> <h3 class="fn"><a name="leading" />int QFontMetrics.leading (<i>self</i>)</h3><p>Returns the leading of the font.</p> <p>This is the natural inter-line spacing.</p> <p><b>See also</b> <a href="qfontmetrics.html#height">height</a>() and <a href="qfontmetrics.html#lineSpacing">lineSpacing</a>().</p> <h3 class="fn"><a name="leftBearing" />int QFontMetrics.leftBearing (<i>self</i>, QChar)</h3><p>Returns the left bearing of character <i>ch</i> in the font.</p> <p>The left bearing is the right-ward 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.</p> <p>See width(<a href="qchar.html">QChar</a>) for a graphical description of this metric.</p> <p><b>See also</b> <a href="qfontmetrics.html#rightBearing">rightBearing</a>(), <a href="qfontmetrics.html#minLeftBearing">minLeftBearing</a>(), and <a href="qfontmetrics.html#width">width</a>().</p> <h3 class="fn"><a name="lineSpacing" />int QFontMetrics.lineSpacing (<i>self</i>)</h3><p>Returns the distance from one base line to the next.</p> <p>This value is always equal to <a href="qfontmetrics.html#leading">leading</a>()+<a href="qfontmetrics.html#height">height</a>().</p> <p><b>See also</b> <a href="qfontmetrics.html#height">height</a>() and <a href="qfontmetrics.html#leading">leading</a>().</p> <h3 class="fn"><a name="lineWidth" />int QFontMetrics.lineWidth (<i>self</i>)</h3><p>Returns the width of the underline and strikeout lines, adjusted for the point size of the font.</p> <p><b>See also</b> <a href="qfontmetrics.html#underlinePos">underlinePos</a>(), <a href="qfontmetrics.html#overlinePos">overlinePos</a>(), and <a href="qfontmetrics.html#strikeOutPos">strikeOutPos</a>().</p> <h3 class="fn"><a name="maxWidth" />int QFontMetrics.maxWidth (<i>self</i>)</h3><p>Returns the width of the widest character in the font.</p> <h3 class="fn"><a name="minLeftBearing" />int QFontMetrics.minLeftBearing (<i>self</i>)</h3><p>Returns the minimum left bearing of the font.</p> <p>This is the smallest leftBearing(char) of all characters in the font.</p> <p>Note that this function can be very slow if the font is large.</p> <p><b>See also</b> <a href="qfontmetrics.html#minRightBearing">minRightBearing</a>() and <a href="qfontmetrics.html#leftBearing">leftBearing</a>().</p> <h3 class="fn"><a name="minRightBearing" />int QFontMetrics.minRightBearing (<i>self</i>)</h3><p>Returns the minimum right bearing of the font.</p> <p>This is the smallest rightBearing(char) of all characters in the font.</p> <p>Note that this function can be very slow if the font is large.</p> <p><b>See also</b> <a href="qfontmetrics.html#minLeftBearing">minLeftBearing</a>() and <a href="qfontmetrics.html#rightBearing">rightBearing</a>().</p> <h3 class="fn"><a name="overlinePos" />int QFontMetrics.overlinePos (<i>self</i>)</h3><p>Returns the distance from the base line to where an overline should be drawn.</p> <p><b>See also</b> <a href="qfontmetrics.html#underlinePos">underlinePos</a>(), <a href="qfontmetrics.html#strikeOutPos">strikeOutPos</a>(), and <a href="qfontmetrics.html#lineWidth">lineWidth</a>().</p> <h3 class="fn"><a name="rightBearing" />int QFontMetrics.rightBearing (<i>self</i>, QChar)</h3><p>Returns the right bearing of character <i>ch</i> in the font.</p> <p>The right bearing is the left-ward 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 <a href="qfontmetrics.html#width">width</a>() of the character.</p> <p>See <a href="qfontmetrics.html#width">width</a>() for a graphical description of this metric.</p> <p><b>See also</b> <a href="qfontmetrics.html#leftBearing">leftBearing</a>(), <a href="qfontmetrics.html#minRightBearing">minRightBearing</a>(), and <a href="qfontmetrics.html#width">width</a>().</p> <h3 class="fn"><a name="size" /><a href="qsize.html">QSize</a> QFontMetrics.size (<i>self</i>, int <i>flags</i>, QString <i>text</i>, int <i>tabStops</i> = 0, list-of-int <i>tabArray</i> = 0)</h3><p>The <i>tabArray</i> argument may also be None.</p><p>Returns the size in pixels of <i>text</i>.</p> <p>The <i>flags</i> argument is the bitwise OR of the following flags:</p> <ul> <li><a href="qt.html#TextFlag-enum">Qt.TextSingleLine</a> ignores newline characters.</li> <li><a href="qt.html#TextFlag-enum">Qt.TextExpandTabs</a> expands tabs (see below)</li> <li><a href="qt.html#TextFlag-enum">Qt.TextShowMnemonic</a> interprets "&x" as <u>x</u>; i.e., underlined.</li> <li>Qt.TextWordBreak breaks the text to fit the rectangle.</li> </ul> <p>If <a href="qt.html#TextFlag-enum">Qt.TextExpandTabs</a> is set in <i>flags</i>, then: if <i>tabArray</i> is non-null, it specifies a 0-terminated sequence of pixel-positions for tabs; otherwise if <i>tabStops</i> is non-zero, it is used as the tab spacing (in pixels).</p> <p>Newline characters are processed as linebreaks.</p> <p>Despite the different actual character heights, the heights of the bounding rectangles of "Yes" and "yes" are the same.</p> <p><b>See also</b> <a href="qfontmetrics.html#boundingRect">boundingRect</a>().</p> <h3 class="fn"><a name="strikeOutPos" />int QFontMetrics.strikeOutPos (<i>self</i>)</h3><p>Returns the distance from the base line to where the strikeout line should be drawn.</p> <p><b>See also</b> <a href="qfontmetrics.html#underlinePos">underlinePos</a>(), <a href="qfontmetrics.html#overlinePos">overlinePos</a>(), and <a href="qfontmetrics.html#lineWidth">lineWidth</a>().</p> <h3 class="fn"><a name="tightBoundingRect" /><a href="qrect.html">QRect</a> QFontMetrics.tightBoundingRect (<i>self</i>, QString <i>text</i>)</h3><p>Returns a tight bounding rectangle around the characters in the string specified by <i>text</i>. The bounding rectangle always covers at least the set of pixels the text would cover if drawn at (0, 0).</p> <p>Note that the bounding rectangle may extend to the left of (0, 0), e.g. for italicized fonts, and that the width of the returned rectangle might be different than what the <a href="qfontmetrics.html#width">width</a>() method returns.</p> <p>If you want to know the advance width of the string (to layout a set of strings next to each other), use <a href="qfontmetrics.html#width">width</a>() instead.</p> <p>Newline characters are processed as normal characters, <i>not</i> as linebreaks.</p> <p><b>Warning:</b> Calling this method is very slow on Windows.</p> <p>This function was introduced in Qt 4.3.</p> <p><b>See also</b> <a href="qfontmetrics.html#width">width</a>(), <a href="qfontmetrics.html#height">height</a>(), and <a href="qfontmetrics.html#boundingRect">boundingRect</a>().</p> <h3 class="fn"><a name="underlinePos" />int QFontMetrics.underlinePos (<i>self</i>)</h3><p>Returns the distance from the base line to where an underscore should be drawn.</p> <p><b>See also</b> <a href="qfontmetrics.html#overlinePos">overlinePos</a>(), <a href="qfontmetrics.html#strikeOutPos">strikeOutPos</a>(), and <a href="qfontmetrics.html#lineWidth">lineWidth</a>().</p> <h3 class="fn"><a name="width" />int QFontMetrics.width (<i>self</i>, QChar)</h3><p>Returns the width in pixels of the first <i>len</i> characters of <i>text</i>. If <i>len</i> is negative (the default), the entire string is used.</p> <p>Note that this value is <i>not</i> equal to <a href="qfontmetrics.html#boundingRect">boundingRect</a>().width(); <a href="qfontmetrics.html#boundingRect">boundingRect</a>() returns a rectangle describing the pixels this string will cover whereas width() returns the distance to where the next string should be drawn.</p> <p><b>See also</b> <a href="qfontmetrics.html#boundingRect">boundingRect</a>().</p> <h3 class="fn"><a name="width-2" />int QFontMetrics.width (<i>self</i>, QString <i>text</i>, int <i>length</i> = -1)</h3><h3 class="fn"><a name="widthChar" />int QFontMetrics.widthChar (<i>self</i>, QChar)</h3><h3 class="fn"><a name="xHeight" />int QFontMetrics.xHeight (<i>self</i>)</h3><p>Returns the 'x' height of the font. This is often but not always the same as the height of the character 'x'.</p> <h3 class="fn"><a name="__eq__" />bool QFontMetrics.__eq__ (<i>self</i>, <a href="qfontmetrics.html">QFontMetrics</a> <i>other</i>)</h3><h3 class="fn"><a name="__ne__" />bool QFontMetrics.__ne__ (<i>self</i>, <a href="qfontmetrics.html">QFontMetrics</a> <i>other</i>)</h3><address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.10.3 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt 4.8.5</td></tr></table></div></address></body></html>