<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <!-- /tmp/qt-4.2.1-harald-1161357942206/qt-x11-opensource-src-4.2.1/src/corelib/tools/qsize.cpp --> <head> <title>Qt 4.2: QSize Class Reference</title> <link href="classic.css" rel="stylesheet" type="text/css" /> </head> <body> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td align="left" valign="top" width="32"><a href="http://www.trolltech.com/products/qt"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></a></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="mainclasses.html"><font color="#004faf">Main Classes</font></a> · <a href="groups.html"><font color="#004faf">Grouped Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a> · <a href="functions.html"><font color="#004faf">Functions</font></a></td> <td align="right" valign="top" width="230"><a href="http://www.trolltech.com"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></a></td></tr></table><h1 align="center">QSize Class Reference<br /><sup><sup>[<a href="qtcore.html">QtCore</a> module]</sup></sup></h1> <p>The QSize class defines the size of a two-dimensional object using integer point precision. <a href="#details">More...</a></p> <pre> #include <QSize></pre><ul> <li><a href="qsize-members.html">List of all members, including inherited members</a></li> </ul> <a name="public-functions"></a> <h3>Public Functions</h3> <ul> <li><div class="fn"/><b><a href="qsize.html#QSize">QSize</a></b> ()</li> <li><div class="fn"/><b><a href="qsize.html#QSize-2">QSize</a></b> ( int <i>width</i>, int <i>height</i> )</li> <li><div class="fn"/>QSize <b><a href="qsize.html#boundedTo">boundedTo</a></b> ( const QSize & <i>otherSize</i> ) const</li> <li><div class="fn"/>QSize <b><a href="qsize.html#expandedTo">expandedTo</a></b> ( const QSize & <i>otherSize</i> ) const</li> <li><div class="fn"/>int <b><a href="qsize.html#height">height</a></b> () const</li> <li><div class="fn"/>bool <b><a href="qsize.html#isEmpty">isEmpty</a></b> () const</li> <li><div class="fn"/>bool <b><a href="qsize.html#isNull">isNull</a></b> () const</li> <li><div class="fn"/>bool <b><a href="qsize.html#isValid">isValid</a></b> () const</li> <li><div class="fn"/>int & <b><a href="qsize.html#rheight">rheight</a></b> ()</li> <li><div class="fn"/>int & <b><a href="qsize.html#rwidth">rwidth</a></b> ()</li> <li><div class="fn"/>void <b><a href="qsize.html#scale">scale</a></b> ( int <i>width</i>, int <i>height</i>, Qt::AspectRatioMode <i>mode</i> )</li> <li><div class="fn"/>void <b><a href="qsize.html#scale-2">scale</a></b> ( const QSize & <i>size</i>, Qt::AspectRatioMode <i>mode</i> )</li> <li><div class="fn"/>void <b><a href="qsize.html#setHeight">setHeight</a></b> ( int <i>height</i> )</li> <li><div class="fn"/>void <b><a href="qsize.html#setWidth">setWidth</a></b> ( int <i>width</i> )</li> <li><div class="fn"/>void <b><a href="qsize.html#transpose">transpose</a></b> ()</li> <li><div class="fn"/>int <b><a href="qsize.html#width">width</a></b> () const</li> <li><div class="fn"/>QSize & <b><a href="qsize.html#operator-2a-eq">operator*=</a></b> ( qreal <i>factor</i> )</li> <li><div class="fn"/>QSize & <b><a href="qsize.html#operator-2b-eq">operator+=</a></b> ( const QSize & <i>size</i> )</li> <li><div class="fn"/>QSize & <b><a href="qsize.html#operator--eq">operator-=</a></b> ( const QSize & <i>size</i> )</li> <li><div class="fn"/>QSize & <b><a href="qsize.html#operator-2f-eq">operator/=</a></b> ( qreal <i>divisor</i> )</li> </ul> <a name="related-non-members"></a> <h3>Related Non-Members</h3> <ul> <li><div class="fn"/>bool <b><a href="qsize.html#operator-not-eq-19">operator!=</a></b> ( const QSize & <i>s1</i>, const QSize & <i>s2</i> )</li> <li><div class="fn"/>const QSize <b><a href="qsize.html#operator-2a-3">operator*</a></b> ( const QSize & <i>size</i>, qreal <i>factor</i> )</li> <li><div class="fn"/>const QSize <b><a href="qsize.html#operator-2a-18">operator*</a></b> ( qreal <i>factor</i>, const QSize & <i>size</i> )</li> <li><div class="fn"/>const QSize <b><a href="qsize.html#operator-2b-6">operator+</a></b> ( const QSize & <i>s1</i>, const QSize & <i>s2</i> )</li> <li><div class="fn"/>const QSize <b><a href="qsize.html#operator--4">operator-</a></b> ( const QSize & <i>s1</i>, const QSize & <i>s2</i> )</li> <li><div class="fn"/>const QSize <b><a href="qsize.html#operator-2f-4">operator/</a></b> ( const QSize & <i>size</i>, qreal <i>divisor</i> )</li> <li><div class="fn"/>QDataStream & <b><a href="qsize.html#operator-lt-lt-58">operator<<</a></b> ( QDataStream & <i>stream</i>, const QSize & <i>size</i> )</li> <li><div class="fn"/>bool <b><a href="qsize.html#operator-eq-eq-28">operator==</a></b> ( const QSize & <i>s1</i>, const QSize & <i>s2</i> )</li> <li><div class="fn"/>QDataStream & <b><a href="qsize.html#operator-gt-gt-32">operator>></a></b> ( QDataStream & <i>stream</i>, QSize & <i>size</i> )</li> </ul> <a name="details"></a> <hr /> <h2>Detailed Description</h2> <p>The QSize class defines the size of a two-dimensional object using integer point precision.</p> <p>A size is specified by a <a href="qsize.html#width">width</a>() and a <a href="qsize.html#height">height</a>(). It can be set in the constructor and changed using the <a href="qsize.html#setWidth">setWidth</a>(), <a href="qsize.html#setHeight">setHeight</a>(), or <a href="qsize.html#scale">scale</a>() functions, or using arithmetic operators. A size can also be manipulated directly by retrieving references to the width and height using the <a href="qsize.html#rwidth">rwidth</a>() and <a href="qsize.html#rheight">rheight</a>() functions. Finally, the width and height can be swapped using the <a href="qsize.html#transpose">transpose</a>() function.</p> <p>The <a href="qsize.html#isValid">isValid</a>() function determines if a size is valid (a valid size has both width and height greater than zero). The <a href="qsize.html#isEmpty">isEmpty</a>() function returns true if either of the width and height is less than, or equal to, zero, while the <a href="qsize.html#isNull">isNull</a>() function returns true only if both the width and the height is zero.</p> <p>Use the <a href="qsize.html#expandedTo">expandedTo</a>() function to retrieve a size which holds the maximum height and width of <i>this</i> size and a given size. Similarily, the <a href="qsize.html#boundedTo">boundedTo</a>() function returns a size which holds the minimum height and width of <i>this</i> size and a given size.</p> <p>QSize objects can be streamed as well as compared.</p> <p>See also <a href="qsizef.html">QSizeF</a>, <a href="qpoint.html">QPoint</a>, and <a href="qrect.html">QRect</a>.</p> <hr /> <h2>Member Function Documentation</h2> <h3 class="fn"><a name="QSize"></a>QSize::QSize ()</h3> <p>Constructs a size with an invalid width and height (i.e., <a href="qsize.html#isValid">isValid</a>() returns false).</p> <p>See also <a href="qsize.html#isValid">isValid</a>().</p> <h3 class="fn"><a name="QSize-2"></a>QSize::QSize ( int <i>width</i>, int <i>height</i> )</h3> <p>Constructs a size with the given <i>width</i> and <i>height</i>.</p> <p>See also <a href="qsize.html#setWidth">setWidth</a>() and <a href="qsize.html#setHeight">setHeight</a>().</p> <h3 class="fn"><a name="boundedTo"></a>QSize QSize::boundedTo ( const QSize & <i>otherSize</i> ) const</h3> <p>Returns a size holding the minimum width and height of this size and the given <i>otherSize</i>.</p> <p>See also <a href="qsize.html#expandedTo">expandedTo</a>() and <a href="qsize.html#scale">scale</a>().</p> <h3 class="fn"><a name="expandedTo"></a>QSize QSize::expandedTo ( const QSize & <i>otherSize</i> ) const</h3> <p>Returns a size holding the maximum width and height of this size and the given <i>otherSize</i>.</p> <p>See also <a href="qsize.html#boundedTo">boundedTo</a>() and <a href="qsize.html#scale">scale</a>().</p> <h3 class="fn"><a name="height"></a>int QSize::height () const</h3> <p>Returns the height.</p> <p>See also <a href="qsize.html#width">width</a>() and <a href="qsize.html#setHeight">setHeight</a>().</p> <h3 class="fn"><a name="isEmpty"></a>bool QSize::isEmpty () const</h3> <p>Returns true if either of the width and height is less than or equal to 0; otherwise returns false.</p> <p>See also <a href="qsize.html#isNull">isNull</a>() and <a href="qsize.html#isValid">isValid</a>().</p> <h3 class="fn"><a name="isNull"></a>bool QSize::isNull () const</h3> <p>Returns true if both the width and height is 0; otherwise returns false.</p> <p>See also <a href="qsize.html#isValid">isValid</a>() and <a href="qsize.html#isEmpty">isEmpty</a>().</p> <h3 class="fn"><a name="isValid"></a>bool QSize::isValid () const</h3> <p>Returns true if both the width and height is equal to or greater than 0; otherwise returns false.</p> <p>See also <a href="qsize.html#isNull">isNull</a>() and <a href="qsize.html#isEmpty">isEmpty</a>().</p> <h3 class="fn"><a name="rheight"></a>int & QSize::rheight ()</h3> <p>Returns a reference to the height.</p> <p>Using a reference makes it possible to manipulate the height directly. For example:</p> <pre> QSize size(100, 10); size.rheight() += 5; <span class="comment"> // size becomes (100,15)</span></pre> <p>See also <a href="qsize.html#rwidth">rwidth</a>() and <a href="qsize.html#setHeight">setHeight</a>().</p> <h3 class="fn"><a name="rwidth"></a>int & QSize::rwidth ()</h3> <p>Returns a reference to the width.</p> <p>Using a reference makes it possible to manipulate the width directly. For example:</p> <pre> QSize size(100, 10); size.rwidth() += 20; <span class="comment"> // size becomes (120,10)</span></pre> <p>See also <a href="qsize.html#rheight">rheight</a>() and <a href="qsize.html#setWidth">setWidth</a>().</p> <h3 class="fn"><a name="scale"></a>void QSize::scale ( int <i>width</i>, int <i>height</i>, <a href="qt.html#AspectRatioMode-enum">Qt::AspectRatioMode</a> <i>mode</i> )</h3> <p>Scales the size to a rectangle with the given <i>width</i> and <i>height</i>, according to the specified <i>mode</i>:</p> <ul> <li>If <i>mode</i> is <a href="qt.html#AspectRatioMode-enum">Qt::IgnoreAspectRatio</a>, the size is set to (<i>width</i>, <i>height</i>).</li> <li>If <i>mode</i> is <a href="qt.html#AspectRatioMode-enum">Qt::KeepAspectRatio</a>, the current size is scaled to a rectangle as large as possible inside (<i>width</i>, <i>height</i>), preserving the aspect ratio.</li> <li>If <i>mode</i> is <a href="qt.html#AspectRatioMode-enum">Qt::KeepAspectRatioByExpanding</a>, the current size is scaled to a rectangle as small as possible outside (<i>width</i>, <i>height</i>), preserving the aspect ratio.</li> </ul> <p>Example:</p> <pre> QSize t1(10, 12); t1.scale(60, 60, Qt::IgnoreAspectRatio); <span class="comment"> // t1 is (60, 60)</span> QSize t2(10, 12); t2.scale(60, 60, Qt::KeepAspectRatio); <span class="comment"> // t2 is (50, 60)</span> QSize t3(10, 12); t3.scale(60, 60, Qt::KeepAspectRatioByExpanding); <span class="comment"> // t3 is (60, 72)</span></pre> <p>See also <a href="qsize.html#setWidth">setWidth</a>() and <a href="qsize.html#setHeight">setHeight</a>().</p> <h3 class="fn"><a name="scale-2"></a>void QSize::scale ( const QSize & <i>size</i>, <a href="qt.html#AspectRatioMode-enum">Qt::AspectRatioMode</a> <i>mode</i> )</h3> <p>This is an overloaded member function, provided for convenience.</p> <p>Scales the size to a rectangle with the given <i>size</i>, according to the specified <i>mode</i>.</p> <h3 class="fn"><a name="setHeight"></a>void QSize::setHeight ( int <i>height</i> )</h3> <p>Sets the height to the given <i>height</i>.</p> <p>See also <a href="qsize.html#rheight">rheight</a>(), <a href="qsize.html#height">height</a>(), and <a href="qsize.html#setWidth">setWidth</a>().</p> <h3 class="fn"><a name="setWidth"></a>void QSize::setWidth ( int <i>width</i> )</h3> <p>Sets the width to the given <i>width</i>.</p> <p>See also <a href="qsize.html#rwidth">rwidth</a>(), <a href="qsize.html#width">width</a>(), and <a href="qsize.html#setHeight">setHeight</a>().</p> <h3 class="fn"><a name="transpose"></a>void QSize::transpose ()</h3> <p>Swaps the width and height values.</p> <p>See also <a href="qsize.html#setWidth">setWidth</a>() and <a href="qsize.html#setHeight">setHeight</a>().</p> <h3 class="fn"><a name="width"></a>int QSize::width () const</h3> <p>Returns the width.</p> <p>See also <a href="qsize.html#height">height</a>() and <a href="qsize.html#setWidth">setWidth</a>().</p> <h3 class="fn"><a name="operator-2a-eq"></a>QSize & QSize::operator*= ( <a href="qtglobal.html#qreal-typedef">qreal</a> <i>factor</i> )</h3> <p>Multiplies both the width and height by the given <i>factor</i>, and returns a reference to the size.</p> <p>Note that the result is rounded to the nearest integer.</p> <p>See also <a href="qsize.html#scale">scale</a>().</p> <h3 class="fn"><a name="operator-2b-eq"></a>QSize & QSize::operator+= ( const QSize & <i>size</i> )</h3> <p>Adds the given <i>size</i> to <i>this</i> size, and returns a reference to this size. For example:</p> <pre> QSize s( 3, 7); QSize r(-1, 4); s += r; <span class="comment"> // s becomes (2,11)</span></pre> <h3 class="fn"><a name="operator--eq"></a>QSize & QSize::operator-= ( const QSize & <i>size</i> )</h3> <p>Subtracts the given <i>size</i> from <i>this</i> size, and returns a reference to this size. For example:</p> <pre> QSize s( 3, 7); QSize r(-1, 4); s -= r; <span class="comment"> // s becomes (4,3)</span></pre> <h3 class="fn"><a name="operator-2f-eq"></a>QSize & QSize::operator/= ( <a href="qtglobal.html#qreal-typedef">qreal</a> <i>divisor</i> )</h3> <p>Divides both the width and height by the given <i>divisor</i>, and returns a reference to the size.</p> <p>Note that the result is rounded to the nearest integer.</p> <p>See also <a href="qsize.html#scale">QSize::scale</a>().</p> <hr /> <h2>Related Non-Members</h2> <h3 class="fn"><a name="operator-not-eq-19"></a>bool operator!= ( const QSize & <i>s1</i>, const QSize & <i>s2</i> )</h3> <p>This is an overloaded member function, provided for convenience.</p> <p>Returns true if <i>s1</i> and <i>s2</i> are different; otherwise returns false.</p> <h3 class="fn"><a name="operator-2a-3"></a>const QSize operator* ( const QSize & <i>size</i>, <a href="qtglobal.html#qreal-typedef">qreal</a> <i>factor</i> )</h3> <p>This is an overloaded member function, provided for convenience.</p> <p>Multiplies the given <i>size</i> by the given <i>factor</i>, and returns the result rounded to the nearest integer.</p> <p>See also <a href="qsize.html#scale">QSize::scale</a>().</p> <h3 class="fn"><a name="operator-2a-18"></a>const QSize operator* ( <a href="qtglobal.html#qreal-typedef">qreal</a> <i>factor</i>, const QSize & <i>size</i> )</h3> <p>This is an overloaded member function, provided for convenience.</p> <p>Multiplies the given <i>size</i> by the given <i>factor</i>, and returns the result rounded to the nearest integer.</p> <h3 class="fn"><a name="operator-2b-6"></a>const QSize operator+ ( const QSize & <i>s1</i>, const QSize & <i>s2</i> )</h3> <p>This is an overloaded member function, provided for convenience.</p> <p>Returns the sum of <i>s1</i> and <i>s2</i>; each component is added separately.</p> <h3 class="fn"><a name="operator--4"></a>const QSize operator- ( const QSize & <i>s1</i>, const QSize & <i>s2</i> )</h3> <p>This is an overloaded member function, provided for convenience.</p> <p>Returns <i>s2</i> subtracted from <i>s1</i>; each component is subtracted separately.</p> <h3 class="fn"><a name="operator-2f-4"></a>const QSize operator/ ( const QSize & <i>size</i>, <a href="qtglobal.html#qreal-typedef">qreal</a> <i>divisor</i> )</h3> <p>This is an overloaded member function, provided for convenience.</p> <p>Divides the given <i>size</i> by the given <i>divisor</i>, and returns the result rounded to the nearest integer.</p> <p>See also <a href="qsize.html#scale">QSize::scale</a>().</p> <h3 class="fn"><a name="operator-lt-lt-58"></a><a href="qdatastream.html">QDataStream</a> & operator<< ( <a href="qdatastream.html">QDataStream</a> & <i>stream</i>, const QSize & <i>size</i> )</h3> <p>This is an overloaded member function, provided for convenience.</p> <p>Writes the given <i>size</i> to the given <i>stream</i>, and returns a reference to the stream.</p> <p>See also <a href="datastreamformat.html">Format of the QDataStream Operators</a>.</p> <h3 class="fn"><a name="operator-eq-eq-28"></a>bool operator== ( const QSize & <i>s1</i>, const QSize & <i>s2</i> )</h3> <p>This is an overloaded member function, provided for convenience.</p> <p>Returns true if <i>s1</i> and <i>s2</i> are equal; otherwise returns false.</p> <h3 class="fn"><a name="operator-gt-gt-32"></a><a href="qdatastream.html">QDataStream</a> & operator>> ( <a href="qdatastream.html">QDataStream</a> & <i>stream</i>, QSize & <i>size</i> )</h3> <p>This is an overloaded member function, provided for convenience.</p> <p>Reads a size from the given <i>stream</i> into the given <i>size</i>, and returns a reference to the stream.</p> <p>See also <a href="datastreamformat.html">Format of the QDataStream Operators</a>.</p> <p /><address><hr /><div align="center"> <table width="100%" cellspacing="0" border="0"><tr class="address"> <td width="30%">Copyright © 2006 <a href="trolltech.html">Trolltech</a></td> <td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td> <td width="30%" align="right"><div align="right">Qt 4.2.1</div></td> </tr></table></div></address></body> </html>