|  | Home · All Classes · Modules

# QPoint Class Reference
[QtCore module]

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

### Methods

- __init__ (self)
- __init__ (self, int, int)
- __init__ (self, QPoint)
- bool isNull (self)
- int manhattanLength (self)
- setX (self, int)
- setY (self, int)
- int x (self)
- int y (self)

### Special Methods

- QPoint __mul__ (self, QMatrix)
- QPoint __mul__ (self, QMatrix4x4)
- QPoint __mul__ (self, QTransform)
- QPoint __add__ (self, QPoint)
- int __bool__ (self)
- QPoint __div__ (self, float)
- bool __eq__ (self, QPoint)
- QPoint __iadd__ (self, QPoint)
- QPoint __idiv__ (self, float)
- QPoint __imul__ (self, float)
- QPoint __isub__ (self, QPoint)
- QPoint __mul__ (self, float)
- bool __ne__ (self, QPoint)
- QPoint __neg__ (self, QPoint)
- str __repr__ (self)
- QPoint __sub__ (self, QPoint)

## 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.

See also QPointF and QPolygon.

## Method Documentation

### QPoint.__init__ (self)

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

See also isNull().

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

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

See also setX() and setY().

### QPoint.__init__ (self, QPoint)

### 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)

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

See also x() and setY().

### QPoint.setY (self, int)

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

See also y() and setX().

### int QPoint.x (self)

Returns the x coordinate of this point.

See also setX() and rx().

### int QPoint.y (self)

Returns the y coordinate of this point.

See also setY() and ry().

### QPoint __mul__ (self, QMatrix)

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

### QPoint __mul__ (self, QMatrix4x4)

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

### QPoint __mul__ (self, QTransform)

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

### QPoint QPoint.__add__ (self, QPoint)

### int QPoint.__bool__ (self)

### QPoint QPoint.__div__ (self, float)

### bool QPoint.__eq__ (self, QPoint)

### QPoint QPoint.__iadd__ (self, QPoint)

### QPoint QPoint.__idiv__ (self, float)

### QPoint QPoint.__imul__ (self, float)

### QPoint QPoint.__isub__ (self, QPoint)

### QPoint QPoint.__mul__ (self, float)

### bool QPoint.__ne__ (self, QPoint)

### QPoint QPoint.__neg__ (self, QPoint)

### str QPoint.__repr__ (self)

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