Home  All Classes  Main Classes  Annotated  Grouped Classes  Functions 
The QPoint class defines a point in the plane. More...
#include <qpoint.h>
A point is specified by an x coordinate and a y coordinate.
The coordinate type is QCOORD (a 32bit integer). The minimum value of QCOORD is QCOORD_MIN (2147483648) and the maximum value is QCOORD_MAX (2147483647).
The coordinates are accessed by the functions x() and y(); they can be set by setX() and setY() or by the reference functions rx() and ry().
Given a point p, the following statements are all equivalent:
p.setX( p.x() + 1 ); p += QPoint( 1, 0 ); p.rx()++;
A QPoint can also be used as a vector. Addition and subtraction of QPoints are defined as for vectors (each component is added separately). You can divide or multiply a QPoint by an int or a double. The function manhattanLength() gives an inexpensive approximation of the length of the QPoint interpreted as a vector.
Example:
//QPoint oldPos is defined somewhere else MyWidget::mouseMoveEvent( QMouseEvent *e ) { QPoint vector = e>pos()  oldPos; if ( vector.manhattanLength() > 3 ) ... //mouse has moved more than 3 pixels since oldPos }
QPoints can be compared for equality or inequality, and they can be written to and read from a QStream.
See also QPointArray, QSize, QRect, Graphics Classes, and Image Processing Classes.
Constructs a point with coordinates (0, 0) (isNull() returns TRUE).
Constructs a point with x value xpos and y value ypos.
Returns TRUE if both the x value and the y value are 0; otherwise returns FALSE.
This is a useful, and quick to calculate, approximation to the true length: sqrt(pow(x(),2)+pow(y(),2)).
Multiplies this point's x and y by c, and returns a reference to this point.
Example:
QPoint p( 1, 4 ); p *= 2; // p becomes (2,8)
Multiplies this point's x and y by c, and returns a reference to this point.
Example:
QPoint p( 1, 4 ); p *= 2.5; // p becomes (3,10)
Note that the result is truncated because points are held as integers.
Adds point p to this point and returns a reference to this point.
Example:
QPoint p( 3, 7 ); QPoint q( 1, 4 ); p += q; // p becomes (2,11)
Subtracts point p from this point and returns a reference to this point.
Example:
QPoint p( 3, 7 ); QPoint q( 1, 4 ); p = q; // p becomes (4,3)
Divides both x and y by c, and returns a reference to this point.
Example:
QPoint p( 2, 8 ); p /= 2; // p becomes (1,4)
Divides both x and y by c, and returns a reference to this point.
Example:
QPoint p( 3, 10 ); p /= 2.5; // p becomes (1,4)
Note that the result is truncated because points are held as integers.
Returns a reference to the x coordinate of the point.
Using a reference makes it possible to directly manipulate x.
Example:
QPoint p( 1, 2 ); p.rx(); // p becomes (0, 2)
See also ry().
Returns a reference to the y coordinate of the point.
Using a reference makes it possible to directly manipulate y.
Example:
QPoint p( 1, 2 ); p.ry()++; // p becomes (1, 3)
See also rx().
Sets the x coordinate of the point to x.
Example: t14/cannon.cpp.
Sets the y coordinate of the point to y.
Example: t14/cannon.cpp.
Returns the x coordinate of the point.
Examples: canvas/canvas.cpp, chart/canvasview.cpp, dirview/dirview.cpp, fileiconview/qfileiconview.cpp, helpsystem/tooltip.cpp, life/life.cpp, and t14/cannon.cpp.
Returns the y coordinate of the point.
Examples: canvas/canvas.cpp, chart/canvasview.cpp, fileiconview/qfileiconview.cpp, helpsystem/tooltip.cpp, life/life.cpp, t14/cannon.cpp, and themes/wood.cpp.
Returns TRUE if p1 and p2 are not equal; otherwise returns FALSE.
Returns the QPoint formed by multiplying both components of p by c.
Returns the QPoint formed by multiplying both components of p by c.
Returns the QPoint formed by multiplying both components of p by c.
Note that the result is truncated because points are held as integers.
Returns the QPoint formed by multiplying both components of p by c.
Note that the result is truncated because points are held as integers.
Returns the sum of p1 and p2; each component is added separately.
Returns p2 subtracted from p1; each component is subtracted separately.
Returns the QPoint formed by changing the sign of both components of p, equivalent to QPoint(0,0)  p.
Returns the QPoint formed by dividing both components of p by c.
Returns the QPoint formed by dividing both components of p by c.
Note that the result is truncated because points are held as integers.
Writes point p to the stream s and returns a reference to the stream.
See also Format of the QDataStream operators.
Returns TRUE if p1 and p2 are equal; otherwise returns FALSE.
Reads a QPoint from the stream s into point p and returns a reference to the stream.
See also Format of the QDataStream operators.
This file is part of the Qt toolkit. Copyright © 19952005 Trolltech. All Rights Reserved.
Copyright © 2005 Trolltech  Trademarks  Qt 3.3.7
