Home · All Classes · Modules

# QPoint Class Reference[QtCore module]

The QPoint class defines a point in the plane using integer precision. More...

## Detailed Description

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.

## Method Documentation

### QPoint.__init__ (self)

Constructs a null point, i.e. with coordinates (0, 0)

### QPoint.__init__ (self, int xpos, int ypos)

Constructs a point with the given coordinates (x, y).

### bool QPoint.isNull (self)

Returns true if both the x and y coordinates are set to 0, otherwise returns false.

### int QPoint.manhattanLength (self)

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.

### QPoint.setX (self, int xpos)

Sets the x coordinate of this point to the given x coordinate.

### QPoint.setY (self, int ypos)

Sets the y coordinate of this point to the given y coordinate.

### int QPoint.x (self)

Returns the x coordinate of this point.

### int QPoint.y (self)

Returns the y coordinate of this point.

### QPoint __mul__ (self, QMatrixm)

This method is only available if the QtGui module is imported.

### QPoint __mul__ (self, QMatrix4x4matrix)

This method is only available if the QtGui module is imported.

### QPoint __mul__ (self, QTransformm)

This method is only available if the QtGui module is imported.

### QPoint QPoint.__sub__ (self, QPointp2)

 PyQt 4.9.4 for Windows Copyright © Riverbank Computing Ltd and Nokia 2012 Qt 4.8.2