主页 | 所有的类 | 主要的类 | 注释的类 | 分组的类 | 函数
QPoint类参考
QPoint类定义了平面上的一个点。 详情请见……
#include
所有成员函数的列表。
公有成员
? ? ? ? ? ? ? ? ? ?
QPoint ()
QPoint ( int xpos, int ypos ) bool isNull () const int x () const int y () const
void setX ( int x ) void setY ( int y )
int manhattanLength () const QCOORD & rx () QCOORD & ry ()
? ? ? ? ? ?
QPoint & operator+= ( const QPoint & p ) QPoint & operator-= ( const QPoint & p ) QPoint & operator*= ( int c ) QPoint & operator*= ( double c ) QPoint & operator/= ( int c ) QPoint & operator/= ( double c )
相关函数
? ? ? ? ? ? ? ? ? ? ? ? ?
bool operator== ( const QPoint & p1, const QPoint & p2 ) bool operator!= ( const QPoint & p1, const QPoint & p2 )
const QPoint operator+ ( const QPoint & p1, const QPoint & p2 ) const QPoint operator- ( const QPoint & p1, const QPoint & p2 ) const QPoint operator* ( const QPoint & p, int c ) const QPoint operator* ( int c, const QPoint & p ) const QPoint operator* ( const QPoint & p, double c ) const QPoint operator* ( double c, const QPoint & p ) const QPoint operator- ( const QPoint & p )
const QPoint operator/ ( const QPoint & p, int c ) const QPoint operator/ ( const QPoint & p, double c )
QDataStream & operator<< ( QDataStream & s, const QPoint & p ) QDataStream & operator>> ( QDataStream & s, QPoint & p )
详细描述
QPoint类定义了平面上的一个点。 一个点由一个x坐标和一个y坐标确定。
坐标类型是QCOORD(一个32位整数)。QCOORD的最小值是QCOORD_MIN(-2147483648),最大值是QCOORD_MAX(2147483647)。 坐标可以通过函数x()和y()来访问,它们可以由setX()和setY()来设置并且由rx()由ry()来参考。 假设一个点p,下面的语句都是等价的:
p.setX( p.x() + 1 ); p += QPoint( 1, 0 ); p.rx()++;
一个QPoint也可以用作是一个矢量。QPoint的加法和减法也像矢量一样定义了(每个分量分别的被相加或者相减)。你可以把一个QPoint与一个int或者一个double做乘法或者除法。函数manhattanLength()像对矢量那样给出了QPoint一个比较廉价的长度接近值的说明。 Example:
//QPoint oldPos在其它什么地方定义过了
MyWidget::mouseMoveEvent( QMouseEvent *e ) {
QPoint vector = e->pos() - oldPos; if ( vector.manhattanLength() > 3 ) ... //鼠标从oldPos移动超过3个象素 }
QPoint可以进行比较得出相等或者不等,并且它们可以写到QStream或者从QStream中读出。 也可以参考QPointArray、QSize、QRect、图形类和图像处理类。
成员函数文档
QPoint::QPoint ()
构造一个坐标为(0,0)的点(isNull()返回真)。 QPoint::QPoint ( int xpos, int ypos ) 构造一个x值为xpos,y值为ypos的点。 bool QPoint::isNull () const
如果x值和y值都是0的话,返回真,否则返回假。 int QPoint::manhattanLength () const
返回x()和y()的绝对值得和,就是传统上的从原点开始的矢量的“曼哈顿长度”。这个传统的出现是因为这样的距离适用于在矩形方格上旅行的履行者们,就像曼哈顿的街道一样。
这个很有用的,并且运算很快,和真实长度sqrt(pow(x(),2)+pow(y(),2))很接近。
QPoint类



