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 數據類型 .