QPointF Class
QPointF 类使用浮点精度定义平面上的点。更多内容...
| 头文件: | #include <QPointF> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
- 所有成员的列表,包括继承的成员
- QPointF 属于绘图类。
注意:该类中的所有函数均为可重入函数。
QPointF 比较
| 类别 | 可比较类型 |
|---|---|
| 相等性 | QPointF |
| 相等性 | QPoint. |
公共函数
| QPointF() | |
| QPointF(const QPoint &point) | |
| QPointF(qreal xpos, qreal ypos) | |
| bool | isNull() const |
| qreal | manhattanLength() const |
| qreal & | rx() |
| qreal & | ry() |
| void | setX(qreal x) |
| void | setY(qreal y) |
| CGPoint | toCGPoint() const |
| QPoint | toPoint() const |
| QPointF | transposed() const |
| qreal | x() const |
| qreal | y() const |
| QPointF & | operator*=(qreal factor) |
| QPointF & | operator+=(const QPointF &point) |
| QPointF & | operator-=(const QPointF &point) |
| QPointF & | operator/=(qreal divisor) |
静态公共成员
| qreal | dotProduct(const QPointF &p1, const QPointF &p2) |
| QPointF | fromCGPoint(CGPoint point) |
相关的非成员
(since 6.8) bool | qFuzzyCompare(const QPointF &p1, const QPointF &p2) |
(since 6.8) bool | qFuzzyIsNull(const QPointF &point) |
| bool | operator!=(const QPointF &lhs, const QPointF &rhs) |
| QPointF | operator*(const QPointF &point, qreal factor) |
| QPointF | operator*(qreal factor, const QPointF &point) |
| QPointF | operator+(const QPointF &point) |
| QPointF | operator+(const QPointF &p1, const QPointF &p2) |
| QPointF | operator-(const QPointF &p1, const QPointF &p2) |
| QPointF | operator-(const QPointF &point) |
| QPointF | operator/(const QPointF &point, qreal divisor) |
| QDataStream & | operator<<(QDataStream &stream, const QPointF &point) |
| bool | operator==(const QPointF &lhs, const QPointF &rhs) |
| QDataStream & | operator>>(QDataStream &stream, QPointF &point) |
详细说明
一个点由 x 坐标和 y 坐标指定,可通过函数x() 和y() 访问。为确保精度,点的坐标使用有限浮点数指定。 当 x 和 y 均设为 0.0 时,isNull() 函数将返回true 。可通过setX() 和setY() 函数设置(或修改)坐标,或者使用rx() 和ry() 函数(这些函数返回对坐标的引用,从而允许直接操作)。
对于给定点p,以下语句均等价:
QPointF 对象也可作为向量使用:加法和减法的定义与向量相同(各分量分别相加)。QPointF 对象还可以与int 或qreal 进行除法或乘法运算。
此外,QPointF类提供了一个构造函数,用于将QPoint 对象转换为QPointF对象,以及一个相应的toPoint()函数,该函数返回该点的 QPoint 副本。最后,QPointF对象既可以进行流式传输,也可以进行比较。
成员函数文档
[constexpr noexcept] QPointF::QPointF()
构造一个原点,即坐标为 (0.0, 0.0) 的点
另请参阅 isNull()。
[constexpr noexcept] QPointF::QPointF(const QPoint &point)
创建给定point 的副本。
另请参阅 toPoint() 和QPoint::toPointF()。
[constexpr noexcept] QPointF::QPointF(qreal xpos, qreal ypos)
根据给定的坐标(xpos ,ypos )构造一个点。
[static constexpr] qreal QPointF::dotProduct(const QPointF &p1, const QPointF &p2)
QPointF p( 3.1, 7.1);
QPointF q(-1.0, 4.1);
qreal dotProduct = QPointF::dotProduct(p, q); // dotProduct becomes 26.01返回p1 与p2 的点积。
[static noexcept] QPointF QPointF::fromCGPoint(CGPoint point)
根据 CGPointpoint 创建一个QRectF 。
另请参阅 toCGPoint()。
[noexcept] bool QPointF::isNull() const
如果 x 和 y 坐标均设置为 0.0(不考虑正负号),则返回 `true `;否则返回 `false`。
[constexpr] qreal QPointF::manhattanLength() const
返回x() 和y() 的绝对值之和,这通常被称为从原点到该点的向量的“曼哈顿长度”。
另请参阅 QPoint::manhattanLength()。
[constexpr noexcept] qreal &QPointF::rx()
返回此点的 x 坐标的引用。
使用引用可以直接操作 x。例如:
QPointF p(1.1, 2.5);
p.rx()--; // p becomes (0.1, 2.5)[constexpr noexcept] qreal &QPointF::ry()
返回此点的 y 坐标引用。
使用引用可以直接操作 y。例如:
QPointF p(1.1, 2.5);
p.ry()++; // p becomes (1.1, 3.5)[constexpr noexcept] void QPointF::setX(qreal x)
将该点的 x 坐标设置为给定的有限坐标x 。
[constexpr noexcept] void QPointF::setY(qreal y)
将该点的 y 坐标设置为给定的有限坐标y 。
[noexcept] CGPoint QPointF::toCGPoint() const
根据QPointF 创建一个CGPoint。
另请参阅 fromCGPoint()。
[constexpr] QPoint QPointF::toPoint() const
将该点的坐标四舍五入到最接近的整数,并返回一个包含四舍五入后坐标的QPoint 对象。
另请参阅 QPointF() 和QPoint::toPointF()。
[constexpr noexcept] QPointF QPointF::transposed() const
返回一个 x 和 y 坐标互换的点:
QPointF{1.0, 2.0}.transposed() // {2.0, 1.0}[constexpr noexcept] qreal QPointF::x() const
返回该点的 x 坐标。
[constexpr noexcept] qreal QPointF::y() const
返回该点的 y 坐标。
[constexpr] QPointF &QPointF::operator*=(qreal factor)
将该点的坐标乘以给定的有限值factor ,并返回该点的引用。例如:
QPointF p(-1.1, 4.1);
p *= 2.5; // p becomes (-2.75, 10.25)另请参阅 operator/=()。
[constexpr] QPointF &QPointF::operator+=(const QPointF &point)
将给定的point 添加到该点,并返回该点的引用。例如:
另请参阅 operator-=()。
[constexpr] QPointF &QPointF::operator-=(const QPointF &point)
从该点减去给定的point ,并返回该点的引用。例如:
另请参阅 operator+=()。
[constexpr] QPointF &QPointF::operator/=(qreal divisor)
将 x 和 y 均除以给定的divisor ,并返回该点的引用。例如:
QPointF p(-2.75, 10.25);
p /= 2.5; // p becomes (-1.1, 4.1)divisor 不能为零或 NaN。
另请参阅 operator*=()。
相关非成员
[constexpr noexcept, since 6.8] bool qFuzzyCompare(const QPointF &p1, const QPointF &p2)
如果 `p1 ` 近似等于 `p2`,则返回 `true `;否则返回 `false`。
该函数在 Qt 6.8 中引入。
另请参阅 qFuzzyIsNull 。
[constexpr noexcept, since 6.8] bool qFuzzyIsNull(const QPointF &point)
如果点point 近似等于点(0.0, 0.0) ,则返回true 。
该函数在 Qt 6.8 中引入。
另请参阅 qFuzzyCompare 。
[constexpr noexcept] bool operator!=(const QPointF &lhs, const QPointF &rhs)
如果lhs 与rhs 存在显著差异,则返回true ;否则返回false 。
警告:此 函数不会检查严格不等关系;而是使用模糊比较来比较点的坐标。
另请参见 qFuzzyCompare 。
[constexpr] QPointF operator*(const QPointF &point, qreal factor)
返回给定point 的副本,并将其与给定的有限factor 相乘。
另请参见 QPointF::operator*=()。
[constexpr] QPointF operator*(qreal factor, const QPointF &point)
返回给定point 的副本,并将其与给定的有限factor 相乘。
这是一个重载函数。
[constexpr] QPointF operator+(const QPointF &point)
返回未修改的point 。
[constexpr] QPointF operator+(const QPointF &p1, const QPointF &p2)
返回一个QPointF 对象,该对象是给定点p1 和p2 的和;每个分量分别相加。
另请参阅 QPointF::operator+=()。
[constexpr] QPointF operator-(const QPointF &p1, const QPointF &p2)
返回一个QPointF 对象,该对象由从p1 中减去p2 得到;每个分量均单独相减。
另请参阅 QPointF::operator-=()。
[constexpr] QPointF operator-(const QPointF &point)
返回一个QPointF 对象,该对象是通过将给定的point 中每个分量的符号翻转而形成的。
等同于 `QPointF(0,0) - point`。
这是一个重载函数。
[constexpr] QPointF operator/(const QPointF &point, qreal divisor)
返回由将给定的point 的每个分量除以给定的divisor 所构成的QPointF 对象。
该divisor 的值不得为零或NaN。
另请参阅 QPointF::operator/=()。
QDataStream &operator<<(QDataStream &stream, const QPointF &point)
将给定的point 写入给定的stream ,并返回该流的引用。
另请参阅 《Qt 数据类型的序列化》。
[constexpr noexcept] bool operator==(const QPointF &lhs, const QPointF &rhs)
如果lhs 近似等于rhs ,则返回true ;否则返回false 。
警告:此 函数不检查严格相等性;而是使用模糊比较来比较点的坐标。
另请参阅 qFuzzyCompare 。
QDataStream &operator>>(QDataStream &stream, QPointF &point)
从给定的stream 中读取一个点,将其写入给定的point ,并返回该流的引用。
另请参阅 《Qt 数据类型的序列化》。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.