QPoint

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

Inheritance diagram of PySide6.QtCore.QPoint

Synopsis

Functions

Static functions

Detailed Description

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() = 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

class PySide6.QtCore.QPoint

PySide6.QtCore.QPoint(QPoint)

PySide6.QtCore.QPoint(xpos, ypos)

Parameters

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

See also

isNull()

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

See also

setX() setY()

PySide6.QtCore.QPoint.__reduce__()
Return type

object

PySide6.QtCore.QPoint.__repr__()
Return type

object

static PySide6.QtCore.QPoint.dotProduct(p1, p2)
Parameters
Return type

int

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

Returns the dot product of p1 and p2.

PySide6.QtCore.QPoint.isNull()
Return type

bool

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

PySide6.QtCore.QPoint.manhattanLength()
Return type

int

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.

PySide6.QtCore.QPoint.__ne__(p2)
Parameters

p2PySide6.QtCore.QPoint

Return type

bool

PySide6.QtCore.QPoint.__mul__(m)
Parameters

mPySide6.QtGui.QTransform

Return type

PySide6.QtCore.QPoint

PySide6.QtCore.QPoint.__mul__(factor)
Parameters

factor – int

Return type

PySide6.QtCore.QPoint

PySide6.QtCore.QPoint.__mul__(factor)
Parameters

factor – int

Return type

PySide6.QtCore.QPoint

PySide6.QtCore.QPoint.__mul__(factor)
Parameters

factor – float

Return type

PySide6.QtCore.QPoint

PySide6.QtCore.QPoint.__mul__(factor)
Parameters

factor – float

Return type

PySide6.QtCore.QPoint

PySide6.QtCore.QPoint.__mul__(factor)
Parameters

factordouble

Return type

PySide6.QtCore.QPoint

PySide6.QtCore.QPoint.__mul__(factor)
Parameters

factordouble

Return type

PySide6.QtCore.QPoint

PySide6.QtCore.QPoint.__mul__(matrix)
Parameters

matrixPySide6.QtGui.QMatrix4x4

Return type

PySide6.QtCore.QPoint

PySide6.QtCore.QPoint.__mul__(matrix)
Parameters

matrixPySide6.QtGui.QMatrix4x4

Return type

PySide6.QtCore.QPoint

Note

This function is deprecated.

PySide6.QtCore.QPoint.__imul__(factor)
Parameters

factor – int

Return type

PySide6.QtCore.QPoint

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

See also

operator/=()

PySide6.QtCore.QPoint.__imul__(factor)
Parameters

factor – float

Return type

PySide6.QtCore.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/=()

PySide6.QtCore.QPoint.__imul__(factor)
Parameters

factordouble

Return type

PySide6.QtCore.QPoint

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/=()

PySide6.QtCore.QPoint.__add__()
Return type

PySide6.QtCore.QPoint

PySide6.QtCore.QPoint.__add__(p2)
Parameters

p2PySide6.QtCore.QPoint

Return type

PySide6.QtCore.QPoint

Returns point unmodified.

PySide6.QtCore.QPoint.__iadd__(p)
Parameters

pPySide6.QtCore.QPoint

Return type

PySide6.QtCore.QPoint

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-=()

PySide6.QtCore.QPoint.__sub__()
Return type

PySide6.QtCore.QPoint

PySide6.QtCore.QPoint.__sub__(p2)
Parameters

p2PySide6.QtCore.QPoint

Return type

PySide6.QtCore.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.

PySide6.QtCore.QPoint.__isub__(p)
Parameters

pPySide6.QtCore.QPoint

Return type

PySide6.QtCore.QPoint

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+=()

PySide6.QtCore.QPoint.__div__(c)
Parameters

c – float

Return type

PySide6.QtCore.QPoint

PySide6.QtCore.QPoint.__idiv__(divisor)
Parameters

divisor – float

Return type

PySide6.QtCore.QPoint

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*=()

PySide6.QtCore.QPoint.__eq__(p2)
Parameters

p2PySide6.QtCore.QPoint

Return type

bool

PySide6.QtCore.QPoint.setX(x)
Parameters

x – int

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

See also

x() setY()

PySide6.QtCore.QPoint.setY(y)
Parameters

y – int

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

See also

y() setX()

PySide6.QtCore.QPoint.toTuple()
Return type

object

PySide6.QtCore.QPoint.transposed()
Return type

PySide6.QtCore.QPoint

Returns a point with x and y coordinates exchanged:

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

See also

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

PySide6.QtCore.QPoint.x()
Return type

int

Returns the x coordinate of this point.

See also

setX() rx()

PySide6.QtCore.QPoint.y()
Return type

int

Returns the y coordinate of this point.

See also

setY() ry()