Qt 常用类 (4)—— QPoint

来源:互联网 发布:专业装修设计软件 编辑:程序博客网 时间:2024/06/04 17:49

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


    构造

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

[plain] view plaincopy
  1. QPoint();    // 构造横纵坐标均为 0 的 QPoint 对象  
  2. QPoint(int x, int y);    // 构造横纵坐标分别为 x 和 y 的 QPont 对象  

    属性

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

[plain] view plaincopy
  1. int &rx();    // 得到横坐标的引用  
  2. int &ry();    // 到到纵坐标的引用  

     注意这些引用都不是只读的,也就是说可以通过它们直接修改 QPoint。

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

[plain] view plaincopy
  1. void setX(int x);    // 设置横坐标为 x  
  2. void setY(int y);    // 设置纵坐标为 y  

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

[plain] view plaincopy
  1. int x() const;    // 获得横坐标  
  2. int y() const;    // 获得纵坐标  



     操作符

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

[plain] view plaincopy
  1. QPoint &operator+=(const QPoint &point);    // 加赋值  
  2. QPoint &operator-=(const QPoint &point);    // 减赋值  

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

[plain] view plaincopy
  1. cosnt QPoint operator+(const QPoint &p1, const QPoint &p2);    // 加法  
  2. const QPoint operator-(const QPoint &p1, const QPoint &p2);     // 减法  
  3. const QPoint operator-(const QPoint &point);                    // 取负数  
  4. bool operator==(const QPoint &p1, const QPoint &p2);            // 判断是否相等  
  5. bool operator!=(const QPoint &p1, const QPoint);                // 判断是否不等  
0 0
原创粉丝点击