QPoint 类使用整数精度定义平面点。 更多...
| 头: | #include <QPoint> | 
| qmake: | QT += core | 
注意: 此类的所有函数 可重入 .
| QPoint (int xpos , int ypos ) | |
| QPoint () | |
| bool | isNull () const | 
| int | manhattanLength () const | 
| int & | rx () | 
| int & | ry () | 
| void | setX (int x ) | 
| void | setY (int y ) | 
| CGPoint | toCGPoint () const | 
| QPoint | transposed () const | 
| int | x () const | 
| int | y () const | 
| QPoint & | operator*= (float factor ) | 
| QPoint & | operator*= (double factor ) | 
| QPoint & | operator*= (int factor ) | 
| QPoint & | operator+= (const QPoint & point ) | 
| QPoint & | operator-= (const QPoint & point ) | 
| QPoint & | operator/= (qreal divisor ) | 
| int | dotProduct (const QPoint & p1 , const QPoint & p2 ) | 
| bool | operator!= (const QPoint & p1 , const QPoint & p2 ) | 
| const QPoint | operator* (const QPoint & point , float factor ) | 
| const QPoint | operator* (float factor , const QPoint & point ) | 
| const QPoint | operator* (const QPoint & point , double factor ) | 
| const QPoint | operator* (double factor , const QPoint & point ) | 
| const QPoint | operator* (const QPoint & point , int factor ) | 
| const QPoint | operator* (int factor , const QPoint & point ) | 
| const QPoint | operator+ (const QPoint & p1 , const QPoint & p2 ) | 
| const QPoint | operator+ (const QPoint & point ) | 
| const QPoint | operator- (const QPoint & p1 , const QPoint & p2 ) | 
| const QPoint | operator- (const QPoint & point ) | 
| const QPoint | operator/ (const QPoint & point , qreal divisor ) | 
| QDataStream & | operator<< (QDataStream & stream , const QPoint & point ) | 
| bool | operator== (const QPoint & p1 , const QPoint & p2 ) | 
| QDataStream & | operator>> (QDataStream & stream , QPoint & point ) | 
						点是通过 X 坐标和 Y 坐标指定,可以访问使用
						
							x
						
						() 和
						
							y
						
						() 函数。
						
							isNull
						
						() 函数返回
						
true
						
						若 x 和 y 两者被设为 0。可以设置 (或变更) 坐标使用
						
							setX
						
						() 和
						
							setY
						
						() 函数,或另外的
						
							rx
						
						() 和
						
							ry
						
						() 函数返回坐标引用 (允许直接操纵)。
					
给定点 p ,下列语句全部等效:
QPoint p; p.setX(p.x() + 1); p += QPoint(1, 0); p.rx()++;
						QPoint 对象还可以用作向量:有为向量 (每个分量各自相加) 定义加法和减法。QPoint 对象也可以除以或乘以
						
int
						
						或
						
qreal
						
						.
					
此外,QPoint 类提供 manhattanLength () 函数会给出廉价近似长度为 QPoint 对象按向量解释。最后,QPoint 对象可以被流化及比较。
构造点采用给定坐标 ( xpos , ypos ).
构造 null 点 (即:采用坐标 (0, 0))
另请参阅 isNull ().
[static]
						
						
							int
						
						QPoint::
						
							dotProduct
						
						(const
						
							
								QPoint
							
						
						&
						
							p1
						
						, const
						
							
								QPoint
							
						
						&
						
							p2
						
						)
						
					QPoint p( 3, 7); QPoint q(-1, 4); int lengthSquared = QPoint::dotProduct(p, q); // lengthSquared becomes 25
返回点积为 p1 and p2 .
该函数在 Qt 5.1 引入。
						返回
						
true
						
						若 X 和 Y 坐标两者被设为 0,否则返回
						
false
						
						.
					
返回绝对值的和对于 x () 和 y (),传统称为从原点到点的向量 "曼哈顿长度"。例如:
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 }
这计算近似真实长度有用且快速:
double trueLength = std::sqrt(std::pow(x(), 2) + std::pow(y(), 2));
"曼哈顿长度" 传统的兴起,是因为这种距离适用于只能按矩形栅格 (像曼哈顿街道) 旅行的旅行者。
返回此点的 X 坐标引用。
使用引用使之可能直接操纵 X。例如:
QPoint p(1, 2); p.rx()--; // p becomes (0, 2)
返回此点的 Y 坐标引用。
使用引用使之可能直接操纵 Y。例如:
QPoint p(1, 2); p.ry()++; // p becomes (1, 3)
将此点的 X 坐标设为给定 x 坐标。
将此点的 Y 坐标设为给定 y 坐标。
创建 CGPoint 从 QPoint .
该函数在 Qt 5.8 引入。
另请参阅 QPointF::fromCGPoint ().
返回具有 x 和 y 交换坐标的点:
QPoint{1, 2}.transposed() // {2, 1}
该函数在 Qt 5.14 引入。
另请参阅 x (), y (), setX (),和 setY ().
返回此点的 X 坐标。
返回此点的 Y 坐标。
将此点的坐标乘以给定 factor ,并返回此点的引用。
注意,结果被四舍五入到最近整数,由于点按整数保持。使用 QPointF 对于浮点精度。
另请参阅 operator/= ().
将此点的坐标乘以给定 factor ,并返回此点的引用。例如:
QPoint p(-1, 4); p *= 2.5; // p becomes (-3, 10)
注意,结果被四舍五入到最近整数,由于点按整数保持。使用 QPointF 对于浮点精度。
另请参阅 operator/= ().
将此点的坐标乘以给定 factor ,并返回此点的引用。
另请参阅 operator/= ().
添加给定 point 到此点并返回此点的引用。例如:
QPoint p( 3, 7); QPoint q(-1, 4); p += q; // p becomes (2, 11)
另请参阅 operator-= ().
减去给定 point 从此点并返回此点的引用。例如:
QPoint p( 3, 7); QPoint q(-1, 4); p -= q; // p becomes (4, 3)
另请参阅 operator+= ().
这是重载函数。
X 和 Y 两者除以给定 divisor ,并返回此点的引用。例如:
QPoint p(-3, 10); p /= 2.5; // p becomes (-1, 4)
注意,结果被四舍五入到最近整数,由于点按整数保持。使用 QPointF 对于浮点精度。
另请参阅 operator*= ().
						返回
						
true
						
						if
						
							p1
						
						and
						
							p2
						
						不相等;则返回
						
false
						
						.
					
返回副本为给定 point 乘以给定 factor .
注意,结果被四舍五入到最近整数,由于点按整数保持。使用 QPointF 对于浮点精度。
另请参阅 QPoint::operator*= ().
这是重载函数。
返回副本为给定 point 乘以给定 factor .
注意,结果被四舍五入到最近整数,由于点按整数保持。使用 QPointF 对于浮点精度。
另请参阅 QPoint::operator*= ().
返回副本为给定 point 乘以给定 factor .
注意,结果被四舍五入到最近整数,由于点按整数保持。使用 QPointF 对于浮点精度。
另请参阅 QPoint::operator*= ().
这是重载函数。
返回副本为给定 point 乘以给定 factor .
注意,结果被四舍五入到最近整数,由于点按整数保持。使用 QPointF 对于浮点精度。
另请参阅 QPoint::operator*= ().
返回副本为给定 point 乘以给定 factor .
另请参阅 QPoint::operator*= ().
这是重载函数。
返回副本为给定 point 乘以给定 factor .
另请参阅 QPoint::operator*= ().
返回 QPoint 对象是和对于给定点 p1 and p2 ;分别相加各分量。
另请参阅 QPoint::operator+= ().
返回 point 未经修改。
该函数在 Qt 5.0 引入。
返回 QPoint 对象的形成是通过减去 p2 from p1 ;分别减去各分量。
另请参阅 QPoint::operator-= ().
这是重载函数。
返回 QPoint 对象的形成是通过改变 2 分量的符号为给定 point .
						相当于
						
QPoint(0,0) - point
						
						.
					
返回 QPoint 的形成是通过除以 2 分量对于给定 point 通过给定 divisor .
注意,结果被四舍五入到最近整数,由于点按整数保持。使用 QPointF 对于浮点精度。
另请参阅 QPoint::operator/= ().
写入给定 point 到给定 stream 并返回流引用。
另请参阅 序列化 Qt 数据类型 .
						返回
						
true
						
						if
						
							p1
						
						and
						
							p2
						
						相等;否则返回 false。
					
读取点从给定 stream 进给定 point 并返回流引用。
另请参阅 序列化 Qt 数据类型 .