class QPoint

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

Synopsis

Methods

Static functions

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

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:

p = QPoint()
p.setX(p.x() + 1)
p += QPoint(1, 0)
p.rx() += 1

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 QPolygon

__init__()

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

See also

isNull()

__init__(xpos, ypos)
Parameters:
  • xpos – int

  • ypos – int

Constructs a point with the given coordinates (xpos, ypos).

See also

setX() setY()

__reduce__()
Return type:

str

__repr__()
Return type:

str

static dotProduct(p1, p2)
Parameters:
Return type:

int

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

p = QPoint( 3, 7)
q = QPoint(-1, 4)
dotProduct = QPoint.dotProduct(p, q) # dotProduct becomes 25()

Returns the dot product of p1 and p2.

isNull()
Return type:

bool

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

manhattanLength()
Return type:

int

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

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:

oldPosition = QPoint()
MyWidget::mouseMoveEvent(QMouseEvent event)

    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:

TrueLength = std::sqrt(std::pow(x(), 2) + std::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.

__ne__(rhs)
Parameters:

rhsQPoint

Return type:

bool

Returns true if lhs and rhs are not equal; otherwise returns false.

__ne__(rhs)
Parameters:

rhsQPointF

Return type:

bool

__mul__(matrix)
Parameters:

matrixQMatrix4x4

Return type:

QPoint

Note

This function is deprecated.

__mul__(matrix)
Parameters:

matrixQMatrix4x4

Return type:

QPoint

__mul__(m)
Parameters:

mQTransform

Return type:

QPoint

__mul__(factor)
Parameters:

factor – float

Return type:

QPoint

This is an overloaded function.

Returns a copy of the given point multiplied by the given factor.

Note that the result is rounded to the nearest integer as points are held as integers. Use QPointF for floating point accuracy.

See also

operator*=()

__mul__(factor)
Parameters:

factor – float

Return type:

QPoint

Returns a copy of the given point multiplied by the given factor.

Note that the result is rounded to the nearest integer as points are held as integers. Use QPointF for floating point accuracy.

See also

operator*=()

__mul__(factor)
Parameters:

factor – float

Return type:

QPoint

This is an overloaded function.

Returns a copy of the given point multiplied by the given factor.

Note that the result is rounded to the nearest integer as points are held as integers. Use QPointF for floating point accuracy.

See also

operator*=()

__mul__(factor)
Parameters:

factor – float

Return type:

QPoint

Returns a copy of the given point multiplied by the given factor.

Note that the result is rounded to the nearest integer as points are held as integers. Use QPointF for floating point accuracy.

See also

operator*=()

__mul__(factor)
Parameters:

factor – int

Return type:

QPoint

This is an overloaded function.

Returns a copy of the given point multiplied by the given factor.

See also

operator*=()

__mul__(factor)
Parameters:

factor – int

Return type:

QPoint

Returns a copy of the given point multiplied by the given factor.

See also

operator*=()

__imul__(factor)
Parameters:

factor – float

Return type:

QPoint

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

Multiplies this point’s coordinates by the given factor, and returns a reference to this point. For example:

p = QPoint(-1, 4)
 = 2.5 # p becomes (-3, 10)

Note that the result is rounded to the nearest integer as points are held as integers. Use QPointF for floating point accuracy.

See also

operator/=()

__imul__(factor)
Parameters:

factor – float

Return type:

QPoint

Multiplies this point’s coordinates by the given factor, and returns a reference to this point.

Note that the result is rounded to the nearest integer as points are held as integers. Use QPointF for floating point accuracy.

See also

operator/=()

__imul__(factor)
Parameters:

factor – int

Return type:

QPoint

Multiplies this point’s coordinates by the given factor, and returns a reference to this point.

See also

operator/=()

__add__()
Return type:

QPoint

Returns point unmodified.

__add__(p2)
Parameters:

p2QPoint

Return type:

QPoint

Returns a QPoint object that is the sum of the given points, p1 and p2; each component is added separately.

See also

operator+=()

__iadd__(p)
Parameters:

pQPoint

Return type:

QPoint

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

Adds the given point to this point and returns a reference to this point. For example:

p = QPoint( 3, 7)
q = QPoint(-1, 4)
p += q # p becomes (2, 11)

See also

operator-=()

__sub__()
Return type:

QPoint

This is an overloaded function.

Returns a QPoint object that is formed by changing the sign of both components of the given point.

Equivalent to QPoint(0,0) - point.

__sub__(p2)
Parameters:

p2QPoint

Return type:

QPoint

Returns a QPoint object that is formed by subtracting p2 from p1; each component is subtracted separately.

See also

operator-=()

__isub__(p)
Parameters:

pQPoint

Return type:

QPoint

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

Subtracts the given point from this point and returns a reference to this point. For example:

p = QPoint( 3, 7)
q = QPoint(-1, 4)
p -= q # p becomes (4, 3)

See also

operator+=()

__div__(c)
Parameters:

c – float

Return type:

QPoint

Returns the QPoint formed by dividing both components of the given point by the given divisor.

Note that the result is rounded to the nearest integer as points are held as integers. Use QPointF for floating point accuracy.

See also

operator/=()

operator/=(divisor)
Parameters:

divisor – float

Return type:

QPoint

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

This is an overloaded function.

Divides both x and y by the given divisor, and returns a reference to this point. For example:

p = QPoint(-3, 10)
p /= 2.5 # p becomes (-1, 4)

Note that the result is rounded to the nearest integer as points are held as integers. Use QPointF for floating point accuracy.

See also

operator*=()

__eq__(rhs)
Parameters:

rhsQPoint

Return type:

bool

Returns true if lhs and rhs are equal; otherwise returns false.

__eq__(rhs)
Parameters:

rhsQPointF

Return type:

bool

setX(x)
Parameters:

x – int

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

See also

x() setY()

setY(y)
Parameters:

y – int

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

See also

y() setX()

toPointF()
Return type:

QPointF

Returns this point as a point with floating point accuracy.

See also

toPoint()

toTuple()
Return type:

object

transposed()
Return type:

QPoint

Returns a point with x and y coordinates exchanged:

QPoint{1, 2}.transposed() // {2, 1}

See also

x() y() setX() setY()

x()
Return type:

int

Returns the x coordinate of this point.

See also

setX() rx()

y()
Return type:

int

Returns the y coordinate of this point.

See also

setY() ry()