<?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"> <!-- qpoint.cpp --> <head> <title>Qt 4.6: QPoint Class Reference</title> <link href="classic.css" rel="stylesheet" type="text/css" /> </head> <body> <a name="//apple_ref/cpp/cl//QPoint"></a> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td align="left" valign="top" width="32"><a href="http://qt.nokia.com/"><img src="images/qt-logo.png" align="left" 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="functions.html"><font color="#004faf">All Functions</font></a> · <a href="overviews.html"><font color="#004faf">Overviews</font></a></td></tr></table><h1 class="title">QPoint Class Reference<br /><span class="small-subtitle">[<a href="qtcore.html">QtCore</a> module]</span> </h1> <p>The QPoint class defines a point in the plane using integer precision. <a href="#details">More...</a></p> <pre> #include <QPoint></pre><ul> <li><a href="qpoint-members.html">List of all members, including inherited members</a></li> </ul> <hr /> <a name="public-functions"></a> <h2>Public Functions</h2> <table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%"> <tr><td class="memItemLeft" align="right" valign="top"></td><td class="memItemRight" valign="bottom"><b><a href="qpoint.html#QPoint">QPoint</a></b> ()</td></tr> <tr><td class="memItemLeft" align="right" valign="top"></td><td class="memItemRight" valign="bottom"><b><a href="qpoint.html#QPoint-2">QPoint</a></b> ( int <i>x</i>, int <i>y</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qpoint.html#isNull">isNull</a></b> () const</td></tr> <tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><b><a href="qpoint.html#manhattanLength">manhattanLength</a></b> () const</td></tr> <tr><td class="memItemLeft" align="right" valign="top">int & </td><td class="memItemRight" valign="bottom"><b><a href="qpoint.html#rx">rx</a></b> ()</td></tr> <tr><td class="memItemLeft" align="right" valign="top">int & </td><td class="memItemRight" valign="bottom"><b><a href="qpoint.html#ry">ry</a></b> ()</td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qpoint.html#setX">setX</a></b> ( int <i>x</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qpoint.html#setY">setY</a></b> ( int <i>y</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><b><a href="qpoint.html#x">x</a></b> () const</td></tr> <tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><b><a href="qpoint.html#y">y</a></b> () const</td></tr> <tr><td class="memItemLeft" align="right" valign="top">QPoint & </td><td class="memItemRight" valign="bottom"><b><a href="qpoint.html#operator-2a-eq">operator*=</a></b> ( qreal <i>factor</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">QPoint & </td><td class="memItemRight" valign="bottom"><b><a href="qpoint.html#operator-2b-eq">operator+=</a></b> ( const QPoint & <i>point</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">QPoint & </td><td class="memItemRight" valign="bottom"><b><a href="qpoint.html#operator--eq">operator-=</a></b> ( const QPoint & <i>point</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">QPoint & </td><td class="memItemRight" valign="bottom"><b><a href="qpoint.html#operator-2f-eq">operator/=</a></b> ( qreal <i>divisor</i> )</td></tr> </table> <hr /> <a name="related-non-members"></a> <h2>Related Non-Members</h2> <table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%"> <tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qpoint.html#operator-not-eq-30">operator!=</a></b> ( const QPoint & <i>p1</i>, const QPoint & <i>p2</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">const QPoint </td><td class="memItemRight" valign="bottom"><b><a href="qpoint.html#operator-2a-55">operator*</a></b> ( qreal <i>factor</i>, const QPoint & <i>point</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">const QPoint </td><td class="memItemRight" valign="bottom"><b><a href="qpoint.html#operator-2a-16">operator*</a></b> ( const QPoint & <i>point</i>, qreal <i>factor</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">const QPoint </td><td class="memItemRight" valign="bottom"><b><a href="qpoint.html#operator-2b-21">operator+</a></b> ( const QPoint & <i>p1</i>, const QPoint & <i>p2</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">const QPoint </td><td class="memItemRight" valign="bottom"><b><a href="qpoint.html#operator--8">operator-</a></b> ( const QPoint & <i>p1</i>, const QPoint & <i>p2</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">const QPoint </td><td class="memItemRight" valign="bottom"><b><a href="qpoint.html#operator--19">operator-</a></b> ( const QPoint & <i>point</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">const QPoint </td><td class="memItemRight" valign="bottom"><b><a href="qpoint.html#operator-2f-2">operator/</a></b> ( const QPoint & <i>point</i>, qreal <i>divisor</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">QDataStream & </td><td class="memItemRight" valign="bottom"><b><a href="qpoint.html#operator-lt-lt-121">operator<<</a></b> ( QDataStream & <i>stream</i>, const QPoint & <i>point</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qpoint.html#operator-eq-eq-52">operator==</a></b> ( const QPoint & <i>p1</i>, const QPoint & <i>p2</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">QDataStream & </td><td class="memItemRight" valign="bottom"><b><a href="qpoint.html#operator-gt-gt-71">operator>></a></b> ( QDataStream & <i>stream</i>, QPoint & <i>point</i> )</td></tr> </table> <a name="details"></a> <hr /> <h2>Detailed Description</h2> <p>The QPoint class defines a point in the plane using integer precision.</p> <p>A point is specified by a x coordinate and an y coordinate which can be accessed using the <a href="qpoint.html#x">x</a>() and <a href="qpoint.html#y">y</a>() functions. The <a href="qpoint.html#isNull">isNull</a>() function returns true if both x and y are set to 0. The coordinates can be set (or altered) using the <a href="qpoint.html#setX">setX</a>() and <a href="qpoint.html#setY">setY</a>() functions, or alternatively the <a href="qpoint.html#rx">rx</a>() and <a href="qpoint.html#ry">ry</a>() functions which return references to the coordinates (allowing direct manipulation).</p> <p>Given a point <i>p</i>, the following statements are all equivalent:</p> <pre> QPoint p; p.setX(p.x() + 1); p += QPoint(1, 0); p.rx()++;</pre> <p>A QPoint object can also be used as a vector: Addition and subtraction are defined as for vectors (each component is added separately). A QPoint object can also be divided or multiplied by an <tt>int</tt> or a <tt>qreal</tt>.</p> <p>In addition, the QPoint class provides the <a href="qpoint.html#manhattanLength">manhattanLength</a>() function which gives an inexpensive approximation of the length of the QPoint object interpreted as a vector. Finally, QPoint objects can be streamed as well as compared.</p> <p>See also <a href="qpointf.html">QPointF</a> and <a href="qpolygon.html">QPolygon</a>.</p> <hr /> <h2>Member Function Documentation</h2> <a name="//apple_ref/cpp/instm/QPoint/QPoint"></a> <h3 class="fn"><a name="QPoint"></a>QPoint::QPoint ()</h3> <p>Constructs a null point, i.e. with coordinates (0, 0)</p> <p>See also <a href="qpoint.html#isNull">isNull</a>().</p> <h3 class="fn"><a name="QPoint-2"></a>QPoint::QPoint ( int <i>x</i>, int <i>y</i> )</h3> <p>Constructs a point with the given coordinates (<i>x</i>, <i>y</i>).</p> <p>See also <a href="qpoint.html#setX">setX</a>() and <a href="qpoint.html#setY">setY</a>().</p> <a name="//apple_ref/cpp/instm/QPoint/isNull"></a> <h3 class="fn"><a name="isNull"></a>bool QPoint::isNull () const</h3> <p>Returns true if both the x and y coordinates are set to 0, otherwise returns false.</p> <a name="//apple_ref/cpp/instm/QPoint/manhattanLength"></a> <h3 class="fn"><a name="manhattanLength"></a>int QPoint::manhattanLength () const</h3> <p>Returns the sum of the absolute values of <a href="qpoint.html#x">x</a>() and <a href="qpoint.html#y">y</a>(), traditionally known as the "Manhattan length" of the vector from the origin to the point. For example:</p> <pre> QPoint oldPosition; MyWidget::mouseMoveEvent(QMouseEvent *event) { QPoint point = event->pos() - oldPosition; if (point.manhattanLength() > 3) <span class="comment">// the mouse has moved more than 3 pixels since the oldPosition</span> }</pre> <p>This is a useful, and quick to calculate, approximation to the true length:</p> <pre> double trueLength = sqrt(pow(x(), 2) + pow(y(), 2));</pre> <p>The tradition of "Manhattan length" arises because such distances apply to travelers who can only travel on a rectangular grid, like the streets of Manhattan.</p> <a name="//apple_ref/cpp/instm/QPoint/rx"></a> <h3 class="fn"><a name="rx"></a>int & QPoint::rx ()</h3> <p>Returns a reference to the x coordinate of this point.</p> <p>Using a reference makes it possible to directly manipulate x. For example:</p> <pre> QPoint p(1, 2); p.rx()--; <span class="comment">// p becomes (0, 2)</span></pre> <p>See also <a href="qpoint.html#x">x</a>() and <a href="qpoint.html#setX">setX</a>().</p> <a name="//apple_ref/cpp/instm/QPoint/ry"></a> <h3 class="fn"><a name="ry"></a>int & QPoint::ry ()</h3> <p>Returns a reference to the y coordinate of this point.</p> <p>Using a reference makes it possible to directly manipulate y. For example:</p> <pre> QPoint p(1, 2); p.ry()++; <span class="comment">// p becomes (1, 3)</span></pre> <p>See also <a href="qpoint.html#y">y</a>() and <a href="qpoint.html#setY">setY</a>().</p> <a name="//apple_ref/cpp/instm/QPoint/setX"></a> <h3 class="fn"><a name="setX"></a>void QPoint::setX ( int <i>x</i> )</h3> <p>Sets the x coordinate of this point to the given <i>x</i> coordinate.</p> <p>See also <a href="qpoint.html#x">x</a>() and <a href="qpoint.html#setY">setY</a>().</p> <a name="//apple_ref/cpp/instm/QPoint/setY"></a> <h3 class="fn"><a name="setY"></a>void QPoint::setY ( int <i>y</i> )</h3> <p>Sets the y coordinate of this point to the given <i>y</i> coordinate.</p> <p>See also <a href="qpoint.html#y">y</a>() and <a href="qpoint.html#setX">setX</a>().</p> <a name="//apple_ref/cpp/instm/QPoint/x"></a> <h3 class="fn"><a name="x"></a>int QPoint::x () const</h3> <p>Returns the x coordinate of this point.</p> <p>See also <a href="qpoint.html#setX">setX</a>() and <a href="qpoint.html#rx">rx</a>().</p> <a name="//apple_ref/cpp/instm/QPoint/y"></a> <h3 class="fn"><a name="y"></a>int QPoint::y () const</h3> <p>Returns the y coordinate of this point.</p> <p>See also <a href="qpoint.html#setY">setY</a>() and <a href="qpoint.html#ry">ry</a>().</p> <a name="//apple_ref/cpp/instm/QPoint/operator*="></a> <h3 class="fn"><a name="operator-2a-eq"></a>QPoint & QPoint::operator*= ( <a href="qtglobal.html#qreal-typedef">qreal</a> <i>factor</i> )</h3> <p>Multiplies this point's coordinates by the given <i>factor</i>, and returns a reference to this point. For example:</p> <pre> QPoint p(-1, 4); p *= 2.5; <span class="comment">// p becomes (-3, 10)</span></pre> <p>Note that the result is rounded to the nearest integer as points are held as integers. Use <a href="qpointf.html">QPointF</a> for floating point accuracy.</p> <p>See also <a href="qpoint.html#operator-2f-eq">operator/=</a>().</p> <a name="//apple_ref/cpp/instm/QPoint/operator+="></a> <h3 class="fn"><a name="operator-2b-eq"></a>QPoint & QPoint::operator+= ( const QPoint & <i>point</i> )</h3> <p>Adds the given <i>point</i> to this point and returns a reference to this point. For example:</p> <pre> QPoint p( 3, 7); QPoint q(-1, 4); p += q; <span class="comment">// p becomes (2, 11)</span></pre> <p>See also <a href="qpoint.html#operator--eq">operator-=</a>().</p> <a name="//apple_ref/cpp/instm/QPoint/operator-="></a> <h3 class="fn"><a name="operator--eq"></a>QPoint & QPoint::operator-= ( const QPoint & <i>point</i> )</h3> <p>Subtracts the given <i>point</i> from this point and returns a reference to this point. For example:</p> <pre> QPoint p( 3, 7); QPoint q(-1, 4); p -= q; <span class="comment">// p becomes (4, 3)</span></pre> <p>See also <a href="qpoint.html#operator-2b-eq">operator+=</a>().</p> <a name="//apple_ref/cpp/instm/QPoint/operator/="></a> <h3 class="fn"><a name="operator-2f-eq"></a>QPoint & QPoint::operator/= ( <a href="qtglobal.html#qreal-typedef">qreal</a> <i>divisor</i> )</h3> <p>This is an overloaded function.</p> <p>Divides both x and y by the given <i>divisor</i>, and returns a reference to this point. For example:</p> <pre> QPoint p(-3, 10); p /= 2.5; <span class="comment">// p becomes (-1, 4)</span></pre> <p>Note that the result is rounded to the nearest integer as points are held as integers. Use <a href="qpointf.html">QPointF</a> for floating point accuracy.</p> <p>See also <a href="qpoint.html#operator-2a-eq">operator*=</a>().</p> <hr /> <h2>Related Non-Members</h2> <h3 class="fn"><a name="operator-not-eq-30"></a>bool operator!= ( const QPoint & <i>p1</i>, const QPoint & <i>p2</i> )</h3> <p>Returns true if <i>p1</i> and <i>p2</i> are not equal; otherwise returns false.</p> <h3 class="fn"><a name="operator-2a-55"></a>const QPoint operator* ( <a href="qtglobal.html#qreal-typedef">qreal</a> <i>factor</i>, const QPoint & <i>point</i> )</h3> <p>This is an overloaded function.</p> <p>Returns a copy of the given <i>point</i> multiplied by the given <i>factor</i>.</p> <h3 class="fn"><a name="operator-2a-16"></a>const QPoint operator* ( const QPoint & <i>point</i>, <a href="qtglobal.html#qreal-typedef">qreal</a> <i>factor</i> )</h3> <p>Returns a copy of the given <i>point</i> multiplied by the given <i>factor</i>.</p> <p>Note that the result is rounded to the nearest integer as points are held as integers. Use <a href="qpointf.html">QPointF</a> for floating point accuracy.</p> <p>See also <a href="qpoint.html#operator-2a-eq">QPoint::operator*=</a>().</p> <h3 class="fn"><a name="operator-2b-21"></a>const QPoint operator+ ( const QPoint & <i>p1</i>, const QPoint & <i>p2</i> )</h3> <p>Returns a <a href="qpoint.html">QPoint</a> object that is the sum of the given points, <i>p1</i> and <i>p2</i>; each component is added separately.</p> <p>See also <a href="qpoint.html#operator-2b-eq">QPoint::operator+=</a>().</p> <h3 class="fn"><a name="operator--8"></a>const QPoint operator- ( const QPoint & <i>p1</i>, const QPoint & <i>p2</i> )</h3> <p>Returns a <a href="qpoint.html">QPoint</a> object that is formed by subtracting <i>p2</i> from <i>p1</i>; each component is subtracted separately.</p> <p>See also <a href="qpoint.html#operator--eq">QPoint::operator-=</a>().</p> <h3 class="fn"><a name="operator--19"></a>const QPoint operator- ( const QPoint & <i>point</i> )</h3> <p>This is an overloaded function.</p> <p>Returns a <a href="qpoint.html">QPoint</a> object that is formed by changing the sign of both components of the given <i>point</i>.</p> <p>Equivalent to <tt>QPoint(0,0) - point</tt>.</p> <h3 class="fn"><a name="operator-2f-2"></a>const QPoint operator/ ( const QPoint & <i>point</i>, <a href="qtglobal.html#qreal-typedef">qreal</a> <i>divisor</i> )</h3> <p>Returns the <a href="qpoint.html">QPoint</a> formed by dividing both components of the given <i>point</i> by the given <i>divisor</i>.</p> <p>Note that the result is rounded to the nearest integer as points are held as integers. Use <a href="qpointf.html">QPointF</a> for floating point accuracy.</p> <p>See also <a href="qpoint.html#operator-2f-eq">QPoint::operator/=</a>().</p> <h3 class="fn"><a name="operator-lt-lt-121"></a><a href="qdatastream.html">QDataStream</a> & operator<< ( <a href="qdatastream.html">QDataStream</a> & <i>stream</i>, const QPoint & <i>point</i> )</h3> <p>Writes the given <i>point</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-52"></a>bool operator== ( const QPoint & <i>p1</i>, const QPoint & <i>p2</i> )</h3> <p>Returns true if <i>p1</i> and <i>p2</i> are equal; otherwise returns false.</p> <h3 class="fn"><a name="operator-gt-gt-71"></a><a href="qdatastream.html">QDataStream</a> & operator>> ( <a href="qdatastream.html">QDataStream</a> & <i>stream</i>, QPoint & <i>point</i> )</h3> <p>Reads a point from the given <i>stream</i> into the given <i>point</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="40%" align="left">Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies)</td> <td width="20%" align="center"><a href="trademarks.html">Trademarks</a></td> <td width="40%" align="right"><div align="right">Qt 4.6.3</div></td> </tr></table></div></address></body> </html>