|  | 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 xpos, int ypos)
- __init__ (self, QPoint)
- bool isNull (self)
- int manhattanLength (self)
- setX (self, int xpos)
- setY (self, int ypos)
- int x (self)
- int y (self)

### Special Methods

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

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

See also isNull().

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

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

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

See also x() and setY().

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

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

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

### QPoint __mul__ (self, QMatrix4x4 matrix)

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

### QPoint __mul__ (self, QTransform m)

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

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

### int QPoint.__bool__ (self)

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

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

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

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

### QPoint QPoint.__imul__ (self, int c)

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

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

### QPoint QPoint.__mul__ (self, int c)

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

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

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

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

### QPoint QPoint.__neg__ (self)

### str QPoint.__repr__ (self)

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