1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Qt Toolkit - 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: white; color: black; }
--></style>
</head><body bgcolor="#ffffff">
<table width="100%">
<tr><td><a href="index.html">
<img width="100" height="100" src="qtlogo.png"
alt="Home" border="0"><img width="100"
height="100" src="face.png" alt="Home" border="0">
</a><td valign=top><div align=right><img src="dochead.png" width="472" height="27"><br>
<a href="classes.html"><b>Classes</b></a>
-<a href="annotated.html">Annotated</a>
- <a href="hierarchy.html">Tree</a>
-<a href="functions.html">Functions</a>
-<a href="index.html">Home</a>
-<a href="topicals.html"><b>Structure</b></a>
</div>
</table>
<h1 align=center>QFontMetrics Class Reference</h1><br clear="all">
<p>
The QFontMetrics class provides font metrics information about fonts.
<a href="#details">More...</a>
<p>
<code>#include <<a href="qfontmetrics-h.html">qfontmetrics.h</a>></code>
<p><a href="qfontmetrics-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li><div class="fn"><a href="#d22d87"><b>QFontMetrics</b></a>(constQFont&)</div>
<li><div class="fn"><a href="#8ed93e"><b>QFontMetrics</b></a>(constQFontMetrics&)</div>
<li><div class="fn"><a href="#f41284"><b>~QFontMetrics</b></a>()</div>
<li><div class="fn">QFontMetrics&<a href="#e1c2e9"><b>operator=</b></a>(constQFontMetrics&)</div>
<li><div class="fn">int<a href="#72c9fb"><b>ascent</b></a>()const</div>
<li><div class="fn">int<a href="#200b74"><b>descent</b></a>()const</div>
<li><div class="fn">int<a href="#341253"><b>height</b></a>()const</div>
<li><div class="fn">int<a href="#c04e17"><b>leading</b></a>()const</div>
<li><div class="fn">int<a href="#e6e380"><b>lineSpacing</b></a>()const</div>
<li><div class="fn">int<a href="#de5799"><b>minLeftBearing</b></a>()const</div>
<li><div class="fn">int<a href="#108c37"><b>minRightBearing</b></a>()const</div>
<li><div class="fn">int<a href="#20f575"><b>maxWidth</b></a>()const</div>
<li><div class="fn">bool<a href="#245094"><b>inFont</b></a>(QChar)const</div>
<li><div class="fn">int<a href="#54cc7d"><b>leftBearing</b></a>(QChar)const</div>
<li><div class="fn">int<a href="#1057f3"><b>rightBearing</b></a>(QChar)const</div>
<li><div class="fn">int<a href="#3b6f39"><b>width</b></a>(constQString&, intlen=-1)const</div>
<li><div class="fn">int<a href="#a6372a"><b>width</b></a>(QChar)const</div>
<li><div class="fn">intwidth(charc)const<em>(obsolete)</em></div>
<li><div class="fn">QRect<a href="#f7aeff"><b>boundingRect</b></a>(constQString&, intlen=-1)const</div>
<li><div class="fn">QRect<a href="#bc3e56"><b>boundingRect</b></a>(QChar)const</div>
<li><div class="fn">QRect<a href="#b1cd55"><b>boundingRect</b></a>(intx, inty, intw, inth, intflags, constQString&str, intlen=-1, inttabstops=0, int*tabarray=0, char**intern=0)const</div>
<li><div class="fn">QSize<a href="#43e1b4"><b>size</b></a>(intflags, constQString&str, intlen=-1, inttabstops=0, int*tabarray=0, char**intern=0)const</div>
<li><div class="fn">int<a href="#cb7ddb"><b>underlinePos</b></a>()const</div>
<li><div class="fn">int<a href="#2963f9"><b>strikeOutPos</b></a>()const</div>
<li><div class="fn">int<a href="#81cc3d"><b>lineWidth</b></a>()const</div>
</ul>
<hr><h2><a name="details"></a>Detailed Description</h2>
The QFontMetrics class provides font metrics information about fonts.
<p>
QFontMetrics functions calculate size of characters and strings for
a given font. There are three ways you can create a QFontMetrics object:
<p>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 can not be a
printer font.
<p><a href="qwidget.html#386569">QWidget::fontMetrics</a>() 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.
<p><a href="qpainter.html#73b2e5">QPainter::fontMetrics</a>() 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).
<p>Once created, the object provides functions to access the individual
metrics of the font, its characters, and for strings rendered in
this font.
<p>There are several functions that operate on the font: <a href="#72c9fb">ascent</a>(),
<a href="#200b74">descent</a>(), <a href="#341253">height</a>(), <a href="#c04e17">leading</a>() and <a href="#e6e380">lineSpacing</a>() return the basic
size properties of the font, and <a href="#cb7ddb">underlinePos</a>(), <a href="#2963f9">strikeOutPos</a>() and
<a href="#81cc3d">lineWidth</a>() return properties of the line that underlines or strikes
out the characters. These functions are all fast.
<p>There are also some functions that operate on the set of glyphs in
the font: <a href="#de5799">minLeftBearing</a>(), <a href="#108c37">minRightBearing</a>() and <a href="#20f575">maxWidth</a>(). These
are by necessity slow, and we recommend avoiding them if possible.
<p>For each character, you can get its <a href="#3b6f39">width</a>(), <a href="#54cc7d">leftBearing</a>() and
<a href="#1057f3">rightBearing</a>() and find out whether it is in the font using
<a href="#245094">inFont</a>(). You can also treat the character as a string, and use the
string functions on it.
<p>The string functions include width(), to return the width of a
string in pixels (or points, for a printer), <a href="#b1cd55">boundingRect</a>(), to
return the rectangle necessary to render a string, and <a href="#43e1b4">size</a>(), to
return the size of that rectangle.
<p>Example:
<pre> <a href="qfont.html">QFont</a> font("times",24);
<a href="qfontmetrics.html">QFontMetrics</a> fm(font);
int w = fm.<a href="#3b6f39">width</a>("What's the width of this text");
int h = fm.<a href="#341253">height</a>();
</pre>
<p>See also <a href="qfont.html">QFont</a> and <a href="qfontinfo.html">QFontInfo</a>.
<p>Examples:
<a href="grapher-grapher-cpp.html#QFontMetrics">grapher/grapher.cpp</a>
<a href="xform-xform-cpp.html#QFontMetrics">xform/xform.cpp</a>
<a href="drawdemo-drawdemo-cpp.html#QFontMetrics">drawdemo/drawdemo.cpp</a>
<a href="scrollview-scrollview-cpp.html#QFontMetrics">scrollview/scrollview.cpp</a>
<a href="movies-main-cpp.html#QFontMetrics">movies/main.cpp</a>
<hr><h2>Member Function Documentation</h2>
<h3 class="fn"><a name="d22d87"></a>QFontMetrics::QFontMetrics(const<a href="qfont.html">QFont</a>&font)</h3>
<p>Constructs a font metrics object for <em>font.</em>
<p>The font must be screen-compatible, i.e. a font you use when drawing
text in <a href="qwidget.html">QWidget</a> or <a href="qpixmap.html">QPixmap</a> objects, not <a href="qpicture.html">QPicture</a> or <a href="qprinter.html">QPrinter</a>.
If <em>font</em> is a printer font, you'll probably get wrong results.
<p>Use <a href="qpainter.html#73b2e5">QPainter::fontMetrics</a>() to get the font metrics when painting.
This is a little slower than using this constructor, but it always
gives correct results.
<h3 class="fn"><a name="8ed93e"></a>QFontMetrics::QFontMetrics(constQFontMetrics&fm)</h3>
<p>Constructs a copy of <em>fm.</em>
<h3 class="fn"><a name="f41284"></a>QFontMetrics::~QFontMetrics()</h3>
<p>Destructs the font metrics object.
<h3 class="fn">int<a name="72c9fb"></a>QFontMetrics::ascent()const</h3>
<p>Returns the maximum ascent of the font.
<p>The ascent is the distance from the base line to the uppermost line
where pixels may be drawn.
<p>See also <a href="#200b74">descent</a>().
<p>Examples:
<a href="drawdemo-drawdemo-cpp.html#ascent">drawdemo/drawdemo.cpp</a>
<a href="scrollview-scrollview-cpp.html#ascent">scrollview/scrollview.cpp</a>
<h3 class="fn"><a href="qrect.html">QRect</a><a name="bc3e56"></a>QFontMetrics::boundingRect(<a href="qchar.html">QChar</a>ch)const</h3>
<p>Returns the bounding rectangle of <em>ch</em> relative to the leftmost
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 the
base line.
<p>See also <a href="#3b6f39">width</a>().
<h3 class="fn"><a href="qrect.html">QRect</a><a name="f7aeff"></a>QFontMetrics::boundingRect(const<a href="qstring.html">QString</a>&str, intlen=-1)const</h3>
<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 drawn at (0,0).
<p>If <em>len</em> is negative (default value), the whole 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 regular characters, <em>not</em> as
linebreaks.
<p>Due to the different actual character heights, the height of the
bounding rectangle of e.g. "Yes" and "yes" may be different.
<p>See also <a href="#3b6f39">width</a>() and <a href="qpainter.html#c89857">QPainter::boundingRect</a>().
<h3 class="fn"><a href="qrect.html">QRect</a><a name="b1cd55"></a>QFontMetrics::boundingRect(intx, inty, intw, inth, intflgs, const<a href="qstring.html">QString</a>&str, intlen=-1, inttabstops=0, int*tabarray=0, char**intern=0)const</h3>
<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 drawn at (0,0). The
drawing, and hence the bounding rectangle, is constrained to the rectangle
<em>(x,y,w,h).</em>
<p>If <em>len</em> is negative (default value), the whole string is used.
<p>The <em>flgs</em> argument is
the bitwise OR of the following flags: <ul>
<li> <code>AlignLeft</code> aligns to the left border.
<li> <code>AlignRight</code> aligns to the right border.
<li> <code>AlignHCenter</code> aligns horizontally centered.
<li> <code>AlignTop</code> aligns to the top border.
<li> <code>AlignBottom</code> aligns to the bottom border.
<li> <code>AlignVCenter</code> aligns vertically centered
<li> <code>AlignCenter</code> (= <code>AlignHCenter</code> | AlignVCenter)
<li> <code>SingleLine</code> ignores newline characters in the text.
<li> <code>ExpandTabs</code> expands tabulators.
<li> <code>ShowPrefix</code> interprets "&x" as "x" underlined.
<li> <code>WordBreak</code> breaks the text to fit the rectangle.
</ul>
<p>Horizontal alignment defaults to AlignLeft and vertical alignment
defaults to AlignTop.
<p>If several of the horizontal or several of the vertical alignment flags
are set, the resulting alignment is undefined.
<p>These flags are defined in <a href="qnamespace-h.html">qnamespace.h</a>.
<p>If <code>ExpandTabs</code> is set in <em>flgs,</em> then:
if <em>tabarray</em> is non.zero, it specifies a 0-terminated sequence
of pixel-positions for tabs; otherwise
if <em>tabstops</em> is non-zero, it is used as the tab spacing (in pixels).
<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 linebreaks.
<p>Despite the different actual character heights, the heights of the
bounding rectangles of "Yes" and "yes" are the same.
<p>The bounding rectangle given by this function is somewhat larger
than that calculated by the simpler boundingRect() function. This
function uses the <a href="#de5799">maximum left</a> and
<a href="#108c37">right</a> font bearings as is necessary
for multi-line text to align correctly. Also, fontHeight() and
<a href="#e6e380">lineSpacing</a>() are used to calculate the height, rather than
individual character heights.
<p>The <em>internal</em> argument is for internal purposes.
<p>See also <a href="#3b6f39">width</a>(), <a href="qpainter.html#c89857">QPainter::boundingRect</a>() and <a href="qt.html#AlignmentFlags">Qt::AlignmentFlags</a>.
<p>Examples:
<a href="xform-xform-cpp.html#boundingRect">xform/xform.cpp</a>
<h3 class="fn">int<a name="200b74"></a>QFontMetrics::descent()const</h3>
<p>Returns the maximum descent of the font.
<p>The 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.)
<p>See also <a href="#72c9fb">ascent</a>().
<p>Examples:
<a href="drawdemo-drawdemo-cpp.html#descent">drawdemo/drawdemo.cpp</a>
<h3 class="fn">int<a name="341253"></a>QFontMetrics::height()const</h3>
<p>Returns the height of the font.
<p>This is always equal to <a href="#72c9fb">ascent</a>()+<a href="#200b74">descent</a>()+1 (the 1 is for the base line).
<p>See also <a href="#c04e17">leading</a>() and <a href="#e6e380">lineSpacing</a>().
<p>Examples:
<a href="grapher-grapher-cpp.html#height">grapher/grapher.cpp</a>
<h3 class="fn">bool<a name="245094"></a>QFontMetrics::inFont(<a href="qchar.html">QChar</a>ch)const</h3>
<p>Returns TRUE if <em>ch</em> is a valid character in the font.
<h3 class="fn">int<a name="c04e17"></a>QFontMetrics::leading()const</h3>
<p>Returns the leading of the font.
<p>This is the natural inter-line spacing.
<p>See also <a href="#341253">height</a>() and <a href="#e6e380">lineSpacing</a>().
<h3 class="fn">int<a name="54cc7d"></a>QFontMetrics::leftBearing(<a href="qchar.html">QChar</a>ch)const</h3>
<p>Returns the left bearing of character <em>ch</em> in the font.
<p>The 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.
<p>See <a href="#3b6f39">width</a>(<a href="qchar.html">QChar</a>) for a graphical description of this metric.
<p>See also <a href="#1057f3">rightBearing</a>(<a href="qchar.html">QChar</a>), <a href="#de5799">minLeftBearing</a>() and <a href="#3b6f39">width</a>().
<h3 class="fn">int<a name="e6e380"></a>QFontMetrics::lineSpacing()const</h3>
<p>Returns the distance from one base line to the next.
<p>This value is always equal to <a href="#c04e17">leading</a>()+<a href="#341253">height</a>().
<p>See also <a href="#341253">height</a>() and <a href="#c04e17">leading</a>().
<p>Examples:
<a href="scrollview-scrollview-cpp.html#lineSpacing">scrollview/scrollview.cpp</a>
<h3 class="fn">int<a name="81cc3d"></a>QFontMetrics::lineWidth()const</h3>
<p>Returns the width of the underline and strike-out lines, adjusted for
the point size of the font.
<p>See also <a href="#cb7ddb">underlinePos</a>() and <a href="#2963f9">strikeOutPos</a>().
<h3 class="fn">int<a name="20f575"></a>QFontMetrics::maxWidth()const</h3>
<p>Returns the width of the widest character in the font.
<h3 class="fn">int<a name="de5799"></a>QFontMetrics::minLeftBearing()const</h3>
<p>Returns the minimum left bearing of the font.
<p>This is the smallest <a href="#54cc7d">leftBearing</a>(char) of all characters in the font.
<p>Note that this function can be very slow if the font is big.
<p>See also <a href="#108c37">minRightBearing</a>() and <a href="#54cc7d">leftBearing</a>(char).
<h3 class="fn">int<a name="108c37"></a>QFontMetrics::minRightBearing()const</h3>
<p>Returns the minimum right bearing of the font.
<p>This is the smallest <a href="#1057f3">rightBearing</a>(char) of all characters in the
font.
<p>Note that this function can be very slow if the font is big.
<p>See also <a href="#de5799">minLeftBearing</a>() and <a href="#1057f3">rightBearing</a>(char).
<h3 class="fn">QFontMetrics&<a name="e1c2e9"></a>QFontMetrics::operator=(constQFontMetrics&fm)</h3>
<p>Font metrics assignment.
<h3 class="fn">int<a name="1057f3"></a>QFontMetrics::rightBearing(<a href="qchar.html">QChar</a>ch)const</h3>
<p>Returns the right bearing of character <em>ch</em> in the font.
<p>The 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 <a href="#3b6f39">width</a>() of the character.
<p>See width() for a graphical description of this metric.
<p>See also <a href="#54cc7d">leftBearing</a>(char), <a href="#108c37">minRightBearing</a>() and <a href="#3b6f39">width</a>().
<h3 class="fn"><a href="qsize.html">QSize</a><a name="43e1b4"></a>QFontMetrics::size(intflgs, const<a href="qstring.html">QString</a>&str, intlen=-1, inttabstops=0, int*tabarray=0, char**intern=0)const</h3>
<p>Returns the size in pixels of the first <em>len</em> characters of <em>str.</em>
<p>If <em>len</em> is negative (default value), the whole string is used.
<p>The <em>flgs</em> argument is
the bitwise OR of the following flags: <ul>
<li> <code>SingleLine</code> ignores newline characters in the text.
<li> <code>ExpandTabs</code> expands tabulators.
<li> <code>ShowPrefix</code> interprets "&x" as "x" underlined.
<li> <code>WordBreak</code> breaks the text to fit the rectangle.
</ul>
<p>These flags are defined in <a href="qnamespace-h.html">qnamespace.h</a>.
<p>If <code>ExpandTabs</code> is set in <em>flgs,</em> then:
if <em>tabarray</em> is non.zero, it specifies a 0-terminated sequence
of pixel-positions for tabs; otherwise
if <em>tabstops</em> is non-zero, it is used as the tab spacing (in pixels).
<p>Newline characters are processed as linebreaks.
<p>Despite the different actual character heights, the heights of the
bounding rectangles of "Yes" and "yes" are the same.
<p>The <em>internal</em> argument is for internal purposes.
<p>See also <a href="#b1cd55">boundingRect</a>().
<h3 class="fn">int<a name="2963f9"></a>QFontMetrics::strikeOutPos()const</h3>
<p>Returns the distance from the base line to where the strike-out line
should be drawn.
<p>See also <a href="#cb7ddb">underlinePos</a>() and <a href="#81cc3d">lineWidth</a>().
<h3 class="fn">int<a name="cb7ddb"></a>QFontMetrics::underlinePos()const</h3>
<p>Returns the distance from the base line to where an underscore should be
drawn.
<p>See also <a href="#2963f9">strikeOutPos</a>() and <a href="#81cc3d">lineWidth</a>().
<h3 class="fn">int<a name="a6372a"></a>QFontMetrics::width(<a href="qchar.html">QChar</a>ch)const</h3>
<p><img src="bearings.png" align=right> Returns the logical width of a
<em>ch</em> in pixels. This is a distance appropriate for drawing a
subsequent character after <em>ch.</em>
<p>Some of the metrics are described in the image to the right. The
tall dark rectangle covers the logical <a href="#3b6f39">width</a>() of a character. The
shorter pale rectangles cover <a href="#54cc7d">leftBearing</a>() and <a href="#1057f3">rightBearing</a>() of
the characters. Notice that the bearings of "f" in this particular
font are both negative, while the bearings of "o" are both positive.
<p>See also <a href="#b1cd55">boundingRect</a>().
<h3 class="fn">int<a name="3b6f39"></a>QFontMetrics::width(const<a href="qstring.html">QString</a>&str, intlen=-1)const</h3>
<p>Returns the width in pixels of the first <em>len</em> characters of <em>str.</em>
<p>If <em>len</em> is negative (the default value is), the whole string is used.
<p>Note that this value is <em>not</em> equal to <a href="#b1cd55">boundingRect</a>().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.
<p>See also <a href="#b1cd55">boundingRect</a>().
<p>Examples:
<a href="drawdemo-drawdemo-cpp.html#width">drawdemo/drawdemo.cpp</a>
<a href="scrollview-scrollview-cpp.html#width">scrollview/scrollview.cpp</a>
<a href="movies-main-cpp.html#width">movies/main.cpp</a>
<h3 class="fn">int<a name="2f88fb"></a>QFontMetrics::width(charc)const</h3>
<p><b>This function is obsolete.</b> 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.<p>This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
<p>Provided to aid porting from Qt 1.x.
<hr><p>
Search the documentation, FAQ, qt-interest archive and more (uses
<a href="http://www.trolltech.com">www.trolltech.com</a>):<br>
<form method=post action="http://www.trolltech.com/search.cgi">
<input type=hidden name="version" value="2.3.2"><nobr>
<input size="50" name="search"><input type=submit value="Search">
</nobr></form><hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>,
copyright © 1995-2001
<a href="http://www.trolltech.com">Trolltech</a>, all rights reserved.<p><address><hr><div align="center">
<table width="100%" cellspacing="0" border="0"><tr>
<td>Copyright 2001 Trolltech<td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align="right"><div align="right">Qt version 2.3.2</div>
</table></div></address></body></html>
|