Qt常用类——Qpoint

QPoint 类代表一个坐标点,实现在 QtCore 共享库中。它可以认为是一个整型的横坐标和一个整型的纵坐标的组合。

构造

QPoint 类支持以下两种构造方式:

QPoint();     // 构造横纵坐标均为 0 的 QPoint 对象  
QPoint(int x, int y);    // 构造横纵坐标分别为 x 和 y 的 QPont 对象  

属性

通过以下成员函数可得到 QPoint 对象中的横纵坐标的引用

int &rx();    // 得到横坐标的引用  
int &ry();    // 到到纵坐标的引用  

通过以下的成员函数可以设置 QPoint 对象中的横纵坐标:

void setX(int x);    // 设置横坐标为 x  
void setY(int y);    // 设置纵坐标为 y  

下面两个成员函数则是只读的,可以获得 QPoint 对象中的横纵坐标:

int x() const;    // 获得横坐标  
int y() const;    // 获得纵坐标 

操作符

QPoint 类支持加法和减法的复合赋值操作:

QPoint &operator+=(const QPoint &point);    // 加赋值  
QPoint &operator-=(const QPoint &point);    // 减赋值 

这两个操作符是它的成员。而以下的操作符则不是它的成员:

const QPoint operator+(const QPoint &p1, const QPoint &p2);    // 加法  
const QPoint operator-(const QPoint &p1, const QPoint &p2);     // 减法  
const QPoint operator-(const QPoint &point);                    // 取负数  
bool operator==(const QPoint &p1, const QPoint &p2);            // 判断是否相等  
bool operator!=(const QPoint &p1, const QPoint);                // 判断是否不等  

 

posted @ 2018-09-29 09:51  cs_wu  阅读(7444)  评论(0编辑  收藏  举报