Home · All Classes · Modules |
The QPoint class defines a point in the plane using integer precision. More...
This class can be pickled.
The QPoint class defines a point in the plane using integer precision.
A point is specified by a x coordinate and an y coordinate which can be accessed using the x() and y() functions. The isNull() function returns true if both x and y are set to 0. The coordinates can be set (or altered) using the setX() and setY() functions, or alternatively the rx() and ry() functions which return references to the coordinates (allowing direct manipulation).
Given a point p, the following statements are all equivalent:
QPoint p; p.setX(p.x() + 1); p += QPoint(1, 0); p.rx()++;
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 int or a qreal.
In addition, the QPoint class provides the manhattanLength() 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.
Constructs a null point, i.e. with coordinates (0, 0)
See also isNull().
Constructs a point with the given coordinates (x, y).
Returns true if both the x and y coordinates are set to 0, otherwise returns false.
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. For example:
QPoint oldPosition; MyWidget.mouseMoveEvent(QMouseEvent *event) { QPoint point = event->pos() - oldPosition; if (point.manhattanLength() > 3) // the mouse has moved more than 3 pixels since the oldPosition }
This is a useful, and quick to calculate, approximation to the true length:
double trueLength = sqrt(pow(x(), 2) + pow(y(), 2));
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.
Sets the x coordinate of this point to the given x coordinate.
Sets the y coordinate of this point to the given y coordinate.
Returns the x coordinate of this point.
Returns the y coordinate of this point.
This method is only available if the QtGui module is imported.
This method is only available if the QtGui module is imported.
This method is only available if the QtGui module is imported.
PyQt 4.12.1 for X11 | Copyright © Riverbank Computing Ltd and The Qt Company 2015 | Qt 4.8.7 |