1
<?xml version="1.0" encoding="iso-8859-1"?>
3
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
<!-- /tmp/qt-4.0.0-espenr-1119621036935/qt-x11-opensource-desktop-4.0.0/src/corelib/tools/qsize.cpp -->
7
<title>Qt 4.0: QSizeF Class Reference</title>
8
<style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
9
a:link { color: #004faf; text-decoration: none }
10
a:visited { color: #672967; text-decoration: none }
11
td.postheader { font-family: sans-serif }
12
tr.address { font-family: sans-serif }
13
body { background: #ffffff; color: black; }</style>
16
<table border="0" cellpadding="0" cellspacing="0" width="100%">
18
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
19
<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="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>
20
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><h1 align="center">QSizeF Class Reference</h1>
21
<p>The QSizeF class defines the size of a two-dimensional object using floating point values for accuracy. <a href="#details">More...</a></p>
22
<pre>#include <QSizeF></pre><p>Part of the <a href="qtcore.html">QtCore</a> module.</p>
24
<li><a href="qsizef-members.html">List of all members, including inherited members</a></li>
26
<a name="public-functions"></a>
27
<h3>Public Functions</h3>
29
<li><div class="fn"/><b><a href="qsizef.html#QSizeF">QSizeF</a></b> ()</li>
30
<li><div class="fn"/><b><a href="qsizef.html#QSizeF-2">QSizeF</a></b> ( const QSize & <i>size</i> )</li>
31
<li><div class="fn"/><b><a href="qsizef.html#QSizeF-3">QSizeF</a></b> ( qreal <i>width</i>, qreal <i>height</i> )</li>
32
<li><div class="fn"/>QSizeF <b><a href="qsizef.html#boundedTo">boundedTo</a></b> ( const QSizeF & <i>otherSize</i> ) const</li>
33
<li><div class="fn"/>QSizeF <b><a href="qsizef.html#expandedTo">expandedTo</a></b> ( const QSizeF & <i>otherSize</i> ) const</li>
34
<li><div class="fn"/>qreal <b><a href="qsizef.html#height">height</a></b> () const</li>
35
<li><div class="fn"/>bool <b><a href="qsizef.html#isEmpty">isEmpty</a></b> () const</li>
36
<li><div class="fn"/>bool <b><a href="qsizef.html#isNull">isNull</a></b> () const</li>
37
<li><div class="fn"/>bool <b><a href="qsizef.html#isValid">isValid</a></b> () const</li>
38
<li><div class="fn"/>qreal & <b><a href="qsizef.html#rheight">rheight</a></b> ()</li>
39
<li><div class="fn"/>qreal & <b><a href="qsizef.html#rwidth">rwidth</a></b> ()</li>
40
<li><div class="fn"/>void <b><a href="qsizef.html#scale">scale</a></b> ( qreal <i>w</i>, qreal <i>h</i>, Qt::AspectRatioMode <i>mode</i> )</li>
41
<li><div class="fn"/>void <b><a href="qsizef.html#scale-2">scale</a></b> ( const QSizeF & <i>s</i>, Qt::AspectRatioMode <i>mode</i> )</li>
42
<li><div class="fn"/>void <b><a href="qsizef.html#setHeight">setHeight</a></b> ( qreal <i>height</i> )</li>
43
<li><div class="fn"/>void <b><a href="qsizef.html#setWidth">setWidth</a></b> ( qreal <i>width</i> )</li>
44
<li><div class="fn"/>QSize <b><a href="qsizef.html#toSize">toSize</a></b> () const</li>
45
<li><div class="fn"/>void <b><a href="qsizef.html#transpose">transpose</a></b> ()</li>
46
<li><div class="fn"/>qreal <b><a href="qsizef.html#width">width</a></b> () const</li>
47
<li><div class="fn"/>QSizeF & <b><a href="qsizef.html#operator-2a-eq">operator*=</a></b> ( qreal <i>coeff</i> )</li>
48
<li><div class="fn"/>QSizeF & <b><a href="qsizef.html#operator-2b-eq">operator+=</a></b> ( const QSizeF & <i>s</i> )</li>
49
<li><div class="fn"/>QSizeF & <b><a href="qsizef.html#operator--eq">operator-=</a></b> ( const QSizeF & <i>s</i> )</li>
50
<li><div class="fn"/>QSizeF & <b><a href="qsizef.html#operator-2f-eq">operator/=</a></b> ( qreal <i>divisor</i> )</li>
52
<a name="related-non-members"></a>
53
<h3>Related Non-Members</h3>
55
<li><div class="fn"/>bool <b><a href="qsizef.html#operator-not-eq-19">operator!=</a></b> ( const QSizeF & <i>s1</i>, const QSizeF & <i>s2</i> )</li>
56
<li><div class="fn"/>const QSizeF <b><a href="qsizef.html#operator-2a-16">operator*</a></b> ( const QSizeF & <i>size</i>, qreal <i>coeff</i> )</li>
57
<li><div class="fn"/>const QSizeF <b><a href="qsizef.html#operator-2a-17">operator*</a></b> ( qreal <i>c</i>, const QSizeF & <i>s</i> )</li>
58
<li><div class="fn"/>const QSizeF <b><a href="qsizef.html#operator-2b-6">operator+</a></b> ( const QSizeF & <i>s1</i>, const QSizeF & <i>s2</i> )</li>
59
<li><div class="fn"/>const QSizeF <b><a href="qsizef.html#operator--5">operator-</a></b> ( const QSizeF & <i>s1</i>, const QSizeF & <i>s2</i> )</li>
60
<li><div class="fn"/>const QSizeF <b><a href="qsizef.html#operator-2f-5">operator/</a></b> ( const QSizeF & <i>size</i>, qreal <i>divisor</i> )</li>
61
<li><div class="fn"/>QDataStream & <b><a href="qsizef.html#operator-lt-lt-50">operator<<</a></b> ( QDataStream & <i>s</i>, const QSizeF & <i>sz</i> )</li>
62
<li><div class="fn"/>bool <b><a href="qsizef.html#operator-eq-eq-26">operator==</a></b> ( const QSizeF & <i>s1</i>, const QSizeF & <i>s2</i> )</li>
63
<li><div class="fn"/>QDataStream & <b><a href="qsizef.html#operator-gt-gt-32">operator>></a></b> ( QDataStream & <i>s</i>, QSizeF & <i>sz</i> )</li>
65
<a name="details"></a>
67
<h2>Detailed Description</h2>
68
<p>The QSizeF class defines the size of a two-dimensional object using floating point values for accuracy.</p>
69
<p>A size is specified by a width and a height.</p>
70
<p>The coordinate type is qreal.</p>
71
<p>The size can be set in the constructor and changed with <a href="qsizef.html#setWidth">setWidth</a>(), <a href="qsizef.html#setHeight">setHeight</a>(), or <a href="qsizef.html#scale">scale</a>(), or using arithmetic operators. You can swap the width and height with <a href="qsizef.html#transpose">transpose</a>(). You can get a size which holds the maximum height and width of two sizes using <a href="qsizef.html#expandedTo">expandedTo</a>(), and the minimum height and width of two sizes using <a href="qsizef.html#boundedTo">boundedTo</a>().</p>
72
<p>See also <a href="qsize.html">QSize</a>, <a href="qpointf.html">QPointF</a>, and <a href="qrectf.html">QRectF</a>.</p>
74
<h2>Member Function Documentation</h2>
75
<h3 class="fn"><a name="QSizeF"></a>QSizeF::QSizeF ()</h3>
76
<p>Constructs an invalid size.</p>
77
<p>See also <a href="qsizef.html#isValid">isValid</a>(), <a href="qsizef.html#setWidth">setWidth</a>(), and <a href="qsizef.html#setHeight">setHeight</a>().</p>
78
<h3 class="fn"><a name="QSizeF-2"></a>QSizeF::QSizeF ( const <a href="qsize.html">QSize</a> & <i>size</i> )</h3>
79
<p>Constructs a size with floating point accuracy from the given <i>size</i>.</p>
80
<h3 class="fn"><a name="QSizeF-3"></a>QSizeF::QSizeF ( <a href="qtglobal.html#qreal-typedef">qreal</a> <i>width</i>, <a href="qtglobal.html#qreal-typedef">qreal</a> <i>height</i> )</h3>
81
<p>Constructs a size with width <i>width</i> and height <i>height</i>.</p>
82
<h3 class="fn"><a name="boundedTo"></a>QSizeF QSizeF::boundedTo ( const QSizeF & <i>otherSize</i> ) const</h3>
83
<p>Returns a size with the minimum width and height of this size and <i>otherSize</i>.</p>
84
<p>See also <a href="qsizef.html#expandedTo">expandedTo</a>(), <a href="qsizef.html#scale">scale</a>(), <a href="qsizef.html#setWidth">setWidth</a>(), and <a href="qsizef.html#setHeight">setHeight</a>().</p>
85
<h3 class="fn"><a name="expandedTo"></a>QSizeF QSizeF::expandedTo ( const QSizeF & <i>otherSize</i> ) const</h3>
86
<p>Returns a size with the maximum width and height of this size and <i>otherSize</i>.</p>
87
<p>See also <a href="qsizef.html#boundedTo">boundedTo</a>(), <a href="qsizef.html#scale">scale</a>(), <a href="qsizef.html#setWidth">setWidth</a>(), and <a href="qsizef.html#setHeight">setHeight</a>().</p>
88
<h3 class="fn"><a name="height"></a><a href="qtglobal.html#qreal-typedef">qreal</a> QSizeF::height () const</h3>
89
<p>Returns the height.</p>
90
<p>See also <a href="qsizef.html#width">width</a>() and <a href="qsizef.html#setHeight">setHeight</a>().</p>
91
<h3 class="fn"><a name="isEmpty"></a>bool QSizeF::isEmpty () const</h3>
92
<p>Returns true if the width is less than or equal to 0, or the height is less than or equal to 0; otherwise returns false.</p>
93
<p>See also <a href="qsizef.html#isNull">isNull</a>(), <a href="qsizef.html#isValid">isValid</a>(), <a href="qsizef.html#width">width</a>(), and <a href="qsizef.html#height">height</a>().</p>
94
<h3 class="fn"><a name="isNull"></a>bool QSizeF::isNull () const</h3>
95
<p>Returns true if the width is 0 and the height is 0; otherwise returns false.</p>
96
<p>See also <a href="qsizef.html#isValid">isValid</a>(), <a href="qsizef.html#isEmpty">isEmpty</a>(), <a href="qsizef.html#width">width</a>(), and <a href="qsizef.html#height">height</a>().</p>
97
<h3 class="fn"><a name="isValid"></a>bool QSizeF::isValid () const</h3>
98
<p>Returns true if the width is equal to or greater than 0 and the height is equal to or greater than 0; otherwise returns false.</p>
99
<p>See also <a href="qsizef.html#isNull">isNull</a>(), <a href="qsizef.html#isEmpty">isEmpty</a>(), <a href="qsizef.html#width">width</a>(), and <a href="qsizef.html#height">height</a>().</p>
100
<h3 class="fn"><a name="rheight"></a><a href="qtglobal.html#qreal-typedef">qreal</a> & QSizeF::rheight ()</h3>
101
<p>Returns a reference to the height.</p>
102
<p>Using a reference makes it possible to directly manipulate the height.</p>
104
<pre> QSizeF s(100, 10.2);
105
s.rheight() += 5.5; // s becomes (100,15.7)</pre>
106
<p>See also <a href="qsizef.html#rwidth">rwidth</a>() and <a href="qsizef.html#setHeight">setHeight</a>().</p>
107
<h3 class="fn"><a name="rwidth"></a><a href="qtglobal.html#qreal-typedef">qreal</a> & QSizeF::rwidth ()</h3>
108
<p>Returns a reference to the width.</p>
109
<p>Using a reference makes it possible to directly manipulate the width.</p>
111
<pre> QSizeF s(100.3, 10);
112
s.rwidth() += 20.5; // s becomes (120.8,10)</pre>
113
<p>See also <a href="qsizef.html#rheight">rheight</a>() and <a href="qsizef.html#setWidth">setWidth</a>().</p>
114
<h3 class="fn"><a name="scale"></a>void QSizeF::scale ( <a href="qtglobal.html#qreal-typedef">qreal</a> <i>w</i>, <a href="qtglobal.html#qreal-typedef">qreal</a> <i>h</i>, <a href="qt.html#AspectRatioMode-enum">Qt::AspectRatioMode</a> <i>mode</i> )</h3>
115
<p>Scales the size to a rectangle of width <i>w</i> and height <i>h</i> according to the <a href="qt.html#AspectRatioMode-enum">Qt::AspectRatioMode</a> <i>mode</i>.</p>
117
<li>If <i>mode</i> is <tt>Qt::IgnoreAspectRatio</tt>, the size is set to (<i>w</i>, <i>h</i>).</li>
118
<li>If <i>mode</i> is <tt>Qt::KeepAspectRatio</tt>, the current size is scaled to a rectangle as large as possible inside (<i>w</i>, <i>h</i>), preserving the aspect ratio.</li>
119
<li>If <i>mode</i> is <tt>Qt::KeepAspectRatioByExpanding</tt>, the current size is scaled to a rectangle as small as possible outside (<i>w</i>, <i>h</i>), preserving the aspect ratio.</li>
122
<pre> QSizeF t1(10, 12);
123
t1.scale(60, 60, QSizeF::IgnoreAspectRatio);
127
t2.scale(60, 60, QSizeF::KeepAspectRatio);
131
t3.scale(60, 60, QSizeF::KeepAspectRatioByExpanding);
132
// t3 is (60, 72)</pre>
133
<p>See also <a href="qsizef.html#boundedTo">boundedTo</a>(), <a href="qsizef.html#expandedTo">expandedTo</a>(), <a href="qsizef.html#setWidth">setWidth</a>(), and <a href="qsizef.html#setHeight">setHeight</a>().</p>
134
<h3 class="fn"><a name="scale-2"></a>void QSizeF::scale ( const QSizeF & <i>s</i>, <a href="qt.html#AspectRatioMode-enum">Qt::AspectRatioMode</a> <i>mode</i> )</h3>
135
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
136
<p>Equivalent to scale(<i>s</i>.<a href="qsizef.html#width">width</a>(), <i>s</i>.<a href="qsizef.html#height">height</a>(), <i>mode</i>).</p>
137
<h3 class="fn"><a name="setHeight"></a>void QSizeF::setHeight ( <a href="qtglobal.html#qreal-typedef">qreal</a> <i>height</i> )</h3>
138
<p>Sets the height to <i>height</i>.</p>
139
<p>See also <a href="qsizef.html#height">height</a>(), <a href="qsizef.html#setWidth">setWidth</a>(), <a href="qsizef.html#expandedTo">expandedTo</a>(), <a href="qsizef.html#boundedTo">boundedTo</a>(), <a href="qsizef.html#scale">scale</a>(), and <a href="qsizef.html#transpose">transpose</a>().</p>
140
<h3 class="fn"><a name="setWidth"></a>void QSizeF::setWidth ( <a href="qtglobal.html#qreal-typedef">qreal</a> <i>width</i> )</h3>
141
<p>Sets the width to <i>width</i>.</p>
142
<p>See also <a href="qsizef.html#width">width</a>(), <a href="qsizef.html#rwidth">rwidth</a>(), <a href="qsizef.html#setHeight">setHeight</a>(), <a href="qsizef.html#expandedTo">expandedTo</a>(), <a href="qsizef.html#boundedTo">boundedTo</a>(), <a href="qsizef.html#scale">scale</a>(), and <a href="qsizef.html#transpose">transpose</a>().</p>
143
<h3 class="fn"><a name="toSize"></a><a href="qsize.html">QSize</a> QSizeF::toSize () const</h3>
144
<p>Returns a size with integer precision. Note that the coordinates in the returned size will be rounded to the nearest integer.</p>
145
<h3 class="fn"><a name="transpose"></a>void QSizeF::transpose ()</h3>
146
<p>Swaps the width and height values.</p>
147
<p>See also <a href="qsizef.html#expandedTo">expandedTo</a>(), <a href="qsizef.html#boundedTo">boundedTo</a>(), <a href="qsizef.html#setWidth">setWidth</a>(), and <a href="qsizef.html#setHeight">setHeight</a>().</p>
148
<h3 class="fn"><a name="width"></a><a href="qtglobal.html#qreal-typedef">qreal</a> QSizeF::width () const</h3>
149
<p>Returns the width.</p>
150
<p>See also <a href="qsizef.html#height">height</a>() and <a href="qsizef.html#setWidth">setWidth</a>().</p>
151
<h3 class="fn"><a name="operator-2a-eq"></a>QSizeF & QSizeF::operator*= ( <a href="qtglobal.html#qreal-typedef">qreal</a> <i>coeff</i> )</h3>
152
<p>Multiplies both the width and height by <i>coeff</i> and returns a reference to the size.</p>
153
<h3 class="fn"><a name="operator-2b-eq"></a>QSizeF & QSizeF::operator+= ( const QSizeF & <i>s</i> )</h3>
154
<p>Adds <i>s</i> to the size and returns a reference to this size.</p>
156
<pre> QSizeF s( 3, 7);
158
s += r; // s becomes (2,11)</pre>
159
<h3 class="fn"><a name="operator--eq"></a>QSizeF & QSizeF::operator-= ( const QSizeF & <i>s</i> )</h3>
160
<p>Subtracts <i>s</i> from the size and returns a reference to this size.</p>
162
<pre> QSizeF s( 3, 7);
164
s -= r; // s becomes (4,3)</pre>
165
<h3 class="fn"><a name="operator-2f-eq"></a>QSizeF & QSizeF::operator/= ( <a href="qtglobal.html#qreal-typedef">qreal</a> <i>divisor</i> )</h3>
166
<p>Divides both the width and height by <i>divisor</i> and returns a reference to the size.</p>
167
<p>See also <a href="qsize.html#scale">QSize::scale</a>().</p>
169
<h2>Related Non-Members</h2>
170
<h3 class="fn"><a name="operator-not-eq-19"></a>bool operator!= ( const QSizeF & <i>s1</i>, const QSizeF & <i>s2</i> )</h3>
171
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
172
<p>Returns true if <i>s1</i> and <i>s2</i> are different; otherwise returns false.</p>
173
<h3 class="fn"><a name="operator-2a-16"></a>const QSizeF operator* ( const QSizeF & <i>size</i>, <a href="qtglobal.html#qreal-typedef">qreal</a> <i>coeff</i> )</h3>
174
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
175
<p>Multiplies <i>size</i> by <i>coeff</i> and returns the result.</p>
176
<p>See also <a href="qsize.html#scale">QSize::scale</a>().</p>
177
<h3 class="fn"><a name="operator-2a-17"></a>const QSizeF operator* ( <a href="qtglobal.html#qreal-typedef">qreal</a> <i>c</i>, const QSizeF & <i>s</i> )</h3>
178
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
179
<p>Multiplies <i>s</i> by <i>c</i> and returns the result.</p>
180
<p>See also <a href="qsize.html#scale">QSize::scale</a>().</p>
181
<h3 class="fn"><a name="operator-2b-6"></a>const QSizeF operator+ ( const QSizeF & <i>s1</i>, const QSizeF & <i>s2</i> )</h3>
182
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
183
<p>Returns the sum of <i>s1</i> and <i>s2</i>; each component is added separately.</p>
184
<h3 class="fn"><a name="operator--5"></a>const QSizeF operator- ( const QSizeF & <i>s1</i>, const QSizeF & <i>s2</i> )</h3>
185
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
186
<p>Returns <i>s2</i> subtracted from <i>s1</i>; each component is subtracted separately.</p>
187
<h3 class="fn"><a name="operator-2f-5"></a>const QSizeF operator/ ( const QSizeF & <i>size</i>, <a href="qtglobal.html#qreal-typedef">qreal</a> <i>divisor</i> )</h3>
188
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
189
<p>Divides <i>size</i> by <i>divisor</i> and returns the result.</p>
190
<p>See also <a href="qsize.html#scale">QSize::scale</a>().</p>
191
<h3 class="fn"><a name="operator-lt-lt-50"></a><a href="qdatastream.html">QDataStream</a> & operator<< ( <a href="qdatastream.html">QDataStream</a> & <i>s</i>, const QSizeF & <i>sz</i> )</h3>
192
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
193
<p>Writes the size <i>sz</i> to the stream <i>s</i> and returns a reference to the stream.</p>
194
<p>See also <a href="datastreamformat.html">Format of the QDataStream
196
<h3 class="fn"><a name="operator-eq-eq-26"></a>bool operator== ( const QSizeF & <i>s1</i>, const QSizeF & <i>s2</i> )</h3>
197
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
198
<p>Returns true if <i>s1</i> and <i>s2</i> are equal; otherwise returns false.</p>
199
<h3 class="fn"><a name="operator-gt-gt-32"></a><a href="qdatastream.html">QDataStream</a> & operator>> ( <a href="qdatastream.html">QDataStream</a> & <i>s</i>, QSizeF & <i>sz</i> )</h3>
200
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
201
<p>Reads the size from the stream <i>s</i> into size <i>sz</i> and returns a reference to the stream.</p>
202
<p>See also <a href="datastreamformat.html">Format of the QDataStream
204
<p /><address><hr /><div align="center">
205
<table width="100%" cellspacing="0" border="0"><tr class="address">
206
<td width="30%">Copyright © 2005 <a href="trolltech.html">Trolltech</a></td>
207
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
208
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
209
</tr></table></div></address></body>