QPoint Class Reference

[ QtCore module]

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

方法

Special Methods


详细描述

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 () 和 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 () 和 setY () functions, or alternatively the rx () 和 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 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.


方法文档编制

QPoint.__init__ ( self )

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

另请参阅 isNull ().

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

构造点采用给定坐标 ( x , y ).

另请参阅 setX () 和 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 () 和 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 坐标。

另请参阅 x () 和 setY ().

QPoint.setY ( self , int  ypos )

Sets the y coordinate of this point to the given y 坐标。

另请参阅 y () 和 setX ().

int QPoint.x ( self )

返回此点的 x 坐标。

另请参阅 setX () 和 rx ().

int QPoint.y ( self )

返回此点的 y 坐标。

另请参阅 setY () 和 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 )