PySide6.QtCore.QPoint¶
- class QPoint¶
The
QPointclass defines a point in the plane using integer precision.Details
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()andy()functions. TheisNull()function returnstrueif both x and y are set to 0. The coordinates can be set (or altered) using thesetX()andsetY()functions, or alternatively therx()andry()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
QPointobject can also be used as a vector: Addition and subtraction are defined as for vectors (each component is added separately). AQPointobject can also be divided or multiplied by anintor aqreal.In addition, the
QPointclass provides themanhattanLength()function which gives an inexpensive approximation of the length of theQPointobject interpreted as a vector. Finally,QPointobjects can be streamed as well as compared.Synopsis¶
Methods¶
def
__init__()def
__reduce__()def
__repr__()def
isNull()def
__ne__()def
__mul__()def
__imul__()def
__add__()def
__iadd__()def
__sub__()def
__isub__()def
__div__()def
operator/=()def
__eq__()def
setX()def
setY()def
toPointF()def
toTuple()def
transposed()def
x()def
y()
Static functions¶
def
dotProduct()
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
- __init__()¶
Constructs a null point, i.e. with coordinates (0, 0)
See also
- __init__(xpos, ypos)
- Parameters:
xpos – int
ypos – int
Constructs a point with the given coordinates (
xpos,ypos).- __reduce__()¶
- Return type:
str
- __repr__()¶
- Return type:
str
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
p1andp2.- isNull()¶
- Return type:
bool
Returns
trueif both the x and y coordinates are set to 0, otherwise returnsfalse.- 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()andy(), 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.
Returns
trueiflhsandrhsare not equal; otherwise returnsfalse.- __ne__(rhs)
- Parameters:
rhs –
QPointF- Return type:
bool
- __mul__(matrix)¶
- Parameters:
matrix –
QMatrix4x4- Return type:
Note
This function is deprecated.
- __mul__(matrix)
- Parameters:
matrix –
QMatrix4x4- Return type:
- __mul__(m)
- Parameters:
m –
QTransform- Return type:
- __mul__(factor)
- Parameters:
factor – float
- Return type:
Returns a copy of the given
pointmultiplied by the givenfactor.Note that the result is rounded to the nearest integer as points are held as integers. Use
QPointFfor floating point accuracy.See also
operator*=()- __mul__(factor)
- Parameters:
factor – float
- Return type:
Returns a copy of the given
pointmultiplied by the givenfactor.Note that the result is rounded to the nearest integer as points are held as integers. Use
QPointFfor floating point accuracy.See also
operator*=()- __mul__(factor)
- Parameters:
factor – float
- Return type:
Returns a copy of the given
pointmultiplied by the givenfactor.Note that the result is rounded to the nearest integer as points are held as integers. Use
QPointFfor floating point accuracy.See also
operator*=()- __mul__(factor)
- Parameters:
factor – float
- Return type:
Returns a copy of the given
pointmultiplied by the givenfactor.Note that the result is rounded to the nearest integer as points are held as integers. Use
QPointFfor floating point accuracy.See also
operator*=()- __mul__(factor)
- Parameters:
factor – int
- Return type:
Returns a copy of the given
pointmultiplied by the givenfactor.See also
operator*=()- __mul__(factor)
- Parameters:
factor – int
- Return type:
Returns a copy of the given
pointmultiplied by the givenfactor.See also
operator*=()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
QPointFfor floating point accuracy.See also
operator/=()- __imul__(factor)
- Parameters:
factor – float
- Return type:
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
QPointFfor floating point accuracy.See also
operator/=()- __imul__(factor)
- Parameters:
factor – int
- Return type:
Multiplies this point’s coordinates by the given
factor, and returns a reference to this point.See also
operator/=()Returns
pointunmodified.Returns a
QPointobject that is the sum of the given points,p1andp2; each component is added separately.See also
operator+=()Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Adds the given
pointto 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-=()Returns a
QPointobject that is formed by changing the sign of both components of the givenpoint.Equivalent to
QPoint(0,0) - point.Returns a
QPointobject that is formed by subtractingp2fromp1; each component is subtracted separately.See also
operator-=()Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Subtracts the given
pointfrom 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+=()Returns the
QPointformed by dividing both components of the givenpointby the givendivisor.Note that the result is rounded to the nearest integer as points are held as integers. Use
QPointFfor floating point accuracy.See also
operator/=()- operator/=(divisor)
- Parameters:
divisor – float
- Return type:
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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
QPointFfor floating point accuracy.See also
operator*=()Returns
trueiflhsandrhsare equal; otherwise returnsfalse.- __eq__(rhs)
- Parameters:
rhs –
QPointF- Return type:
bool
- setX(x)¶
- Parameters:
x – int
Sets the x coordinate of this point to the given
xcoordinate.- setY(y)¶
- Parameters:
y – int
Sets the y coordinate of this point to the given
ycoordinate.Returns this point as a point with floating point accuracy.
See also
- toTuple()¶
- Return type:
object
Returns a point with x and y coordinates exchanged:
- 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()