A point is specified by an x coordinate and a y coordinate.
.PP
The coordinate type is \fCQCOORD\fR (a 32-bit integer). The minimum value of \fCQCOORD\fR is \fCQCOORD_MIN\fR (-2147483648) and the maximum value is \fCQCOORD_MAX\fR (2147483647).
.PP
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().
.PP
Given a point \fIp\fR, the following statements are all equivalent:
.PP
.nf
.br
p.setX( p.x() + 1 );
.br
p += QPoint( 1, 0 );
.br
p.rx()++;
.br
.fi
.PP
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 \fCint\fR or a \fCdouble\fR. The function manhattanLength() gives an inexpensive approximation of the length of the QPoint interpreted as a vector.
.PP
Example:
.PP
.nf
.br
//QPoint oldPos is defined somewhere else
.br
MyWidget::mouseMoveEvent( QMouseEvent *e )
.br
{
.br
QPoint vector = e->pos() - oldPos;
.br
if ( vector.manhattanLength() > 3 )
.br
... //mouse has moved more than 3 pixels since oldPos
.br
}
.br
.fi
.PP
QPoints can be compared for equality or inequality, and they can be written to and read from a QStream.
.PP
See also QPointArray, QSize, QRect, Graphics Classes, and Image Processing Classes.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QPoint::QPoint ()"
Constructs a point with coordinates (0, 0) (isNull() returns TRUE).
.SH "QPoint::QPoint ( int xpos, int ypos )"
Constructs a point with x value \fIxpos\fR and y value \fIypos\fR.
.SH "bool QPoint::isNull () const"
Returns TRUE if both the x value and the y value are 0; otherwise returns FALSE.
.SH "int QPoint::manhattanLength () const"
Returns the sum of the absolute values of x() and y(), traditionally known as the "Manhattan length" of the vector from the origin to the point. The tradition arises because such distances apply to travelers who can only travel on a rectangular grid, like the streets of Manhattan.
.PP
This is a useful, and tquick to calculate, approximation to the true length: sqrt(pow(x(),2)+pow(y(),2)).
.SH "QPoint & QPoint::operator*= ( int c )"
Multiplies this point's x and y by \fIc\fR, and returns a reference to this point.
.PP
Example:
.PP
.nf
.br
QPoint p( -1, 4 );
.br
p *= 2; // p becomes (-2,8)
.br
.fi
.SH "QPoint & QPoint::operator*= ( double c )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Multiplies this point's x and y by \fIc\fR, and returns a reference to this point.
.PP
Example:
.PP
.nf
.br
QPoint p( -1, 4 );
.br
p *= 2.5; // p becomes (-3,10)
.br
.fi
.PP
Note that the result is truncated because points are held as integers.
.SH "QPoint & QPoint::operator+= ( const QPoint & p )"
Adds point \fIp\fR to this point and returns a reference to this point.
.PP
Example:
.PP
.nf
.br
QPoint p( 3, 7 );
.br
QPoint q( -1, 4 );
.br
p += q; // p becomes (2,11)
.br
.fi
.SH "QPoint & QPoint::operator-= ( const QPoint & p )"
Subtracts point \fIp\fR from this point and returns a reference to this point.
.PP
Example:
.PP
.nf
.br
QPoint p( 3, 7 );
.br
QPoint q( -1, 4 );
.br
p -= q; // p becomes (4,3)
.br
.fi
.SH "QPoint & QPoint::operator/= ( int c )"
Divides both x and y by \fIc\fR, and returns a reference to this point.
.PP
Example:
.PP
.nf
.br
QPoint p( -2, 8 );
.br
p /= 2; // p becomes (-1,4)
.br
.fi
.SH "QPoint & QPoint::operator/= ( double c )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Divides both x and y by \fIc\fR, and returns a reference to this point.
.PP
Example:
.PP
.nf
.br
QPoint p( -3, 10 );
.br
p /= 2.5; // p becomes (-1,4)
.br
.fi
.PP
Note that the result is truncated because points are held as integers.
.SH "QCOORD & QPoint::rx ()"
Returns a reference to the x coordinate of the point.
.PP
Using a reference makes it possible to directly manipulate x.
.PP
Example:
.PP
.nf
.br
QPoint p( 1, 2 );
.br
p.rx()--; // p becomes (0, 2)
.br
.fi
.PP
See also ry().
.SH "QCOORD & QPoint::ry ()"
Returns a reference to the y coordinate of the point.
.PP
Using a reference makes it possible to directly manipulate y.
.PP
Example:
.PP
.nf
.br
QPoint p( 1, 2 );
.br
p.ry()++; // p becomes (1, 3)
.br
.fi
.PP
See also rx().
.SH "void QPoint::setX ( int x )"
Sets the x coordinate of the point to \fIx\fR.
.PP
See also x() and setY().
.PP
Example: t14/cannon.cpp.
.SH "void QPoint::setY ( int y )"
Sets the y coordinate of the point to \fIy\fR.
.PP
See also y() and setX().
.PP
Example: t14/cannon.cpp.
.SH "int QPoint::x () const"
Returns the x coordinate of the point.
.PP
See also setX() and y().
.PP
Examples:
.)l canvas/canvas.cpp, chart/canvasview.cpp, dirview/dirview.cpp, fileiconview/qfileiconview.cpp, helpsystem/tooltip.cpp, life/life.cpp, and t14/cannon.cpp.
.SH "int QPoint::y () const"
Returns the y coordinate of the point.
.PP
See also setY() and x().
.PP
Examples:
.)l canvas/canvas.cpp, chart/canvasview.cpp, fileiconview/qfileiconview.cpp, helpsystem/tooltip.cpp, life/life.cpp, t14/cannon.cpp, and themes/wood.cpp.