QGraphicsRotation Class
QGraphicsRotation 类提供了围绕给定轴的旋转变换。更多内容...
| 头文件: | #include <QGraphicsRotation> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Widgets) target_link_libraries(mytarget PRIVATE Qt6::Widgets) |
| qmake: | QT += widgets |
| 继承自: | QGraphicsTransform |
属性
公共函数
| QGraphicsRotation(QObject *parent = nullptr) | |
| virtual | ~QGraphicsRotation() |
| qreal | angle() const |
| QVector3D | axis() const |
| QVector3D | origin() const |
| void | setAngle(qreal) |
| void | setAxis(const QVector3D &axis) |
| void | setAxis(Qt::Axis axis) |
| void | setOrigin(const QVector3D &point) |
重新实现的公共函数
| virtual void | applyTo(QMatrix4x4 *matrix) const override |
信号
| void | angleChanged() |
| void | axisChanged() |
| void | originChanged() |
详细说明
您可以通过将QVector3D 赋值给axis属性,或者将Qt::Axis 的成员传递给setAxis 便捷函数,来指定所需的旋转轴。默认情况下,旋转轴为(0, 0, 1),即围绕Z轴旋转。
由 QGraphicsRotation 提供的 angle 属性,现在用于描述围绕该轴旋转的度数。
QGraphicsRotation 提供了一些参数,用于控制旋转的实施方式。
原点是指项目围绕其旋转的点(即,当项目的其余部分旋转时,该点相对于父项保持固定)。默认情况下,原点为QPointF (0, 0)。
angle 属性指定项目以顺时针方向围绕原点旋转的度数。该值也可以是负数,表示逆时针旋转。出于动画效果的考虑,提供超过 (-360, 360) 度的旋转角度可能会很有用,例如用于动画展示项目旋转数圈的效果。
注意:最终的旋转效果是三维空间旋转与随后投影回二维空间的综合结果。如果连续执行多次旋转,除非它们均围绕 Z 轴进行,否则结果可能与预期不符。
另请参阅 QGraphicsTransform 、QGraphicsItem::setRotation() 以及QTransform::rotate()。
属性文档
angle : qreal
该属性存储顺时针旋转的角度(单位为度)。
角度可以是任意实数;默认值为 0.0。值为 180 时,将顺时针旋转 180 度。如果提供负数,则项目将逆时针旋转。 通常,旋转角度应在 (-360, 360) 范围内,但您也可以提供此范围外的数值(例如,370 度的角度与 10 度的结果相同)。将角度设置为 NaN 时,将不进行旋转。
访问函数:
| qreal | angle() const |
| void | setAngle(qreal) |
通知信号:
| void | angleChanged() |
另请参阅 origin。
axis : QVector3D
该属性包含一个旋转轴,由三维空间中的一个向量指定。
该轴可以是三维空间中的任意轴。 默认情况下,该轴为 (0, 0, 1),与 Z 轴对齐。如果您指定了另一个轴,QGraphicsRotation 将提供一个围绕该轴旋转的变换。例如,如果您希望围绕某项的 X 轴进行旋转,可以将 (1, 0, 0) 作为轴传入。
访问函数:
| QVector3D | axis() const |
| void | setAxis(const QVector3D &axis) |
| void | setAxis(Qt::Axis axis) |
通知信号:
| void | axisChanged() |
另请参阅 QTransform 和QGraphicsRotation::angle 。
origin : QVector3D
该属性存储了三维空间中旋转的原点。
所有旋转操作都将以此点为基准进行(即,当对象旋转时,该点相对于父对象将保持固定)。
访问函数:
| QVector3D | origin() const |
| void | setOrigin(const QVector3D &point) |
通知信号:
| void | originChanged() |
另请参阅 angle 。
成员函数文档
QGraphicsRotation::QGraphicsRotation(QObject *parent = nullptr)
使用给定的parent 创建一个新的QGraphicsRotation对象。
[virtual noexcept] QGraphicsRotation::~QGraphicsRotation()
会破坏图形旋转。
[signal] void QGraphicsRotation::angleChanged()
每当角度发生变化时,都会发出此信号。
注意: 这是属性 `angle`的通知 信号。
另请参阅 QGraphicsRotation::angle 。
[override virtual] void QGraphicsRotation::applyTo(QMatrix4x4 *matrix) const
重新实现了:QGraphicsTransform::applyTo(QMatrix4x4 *matrix) const。
[signal] void QGraphicsRotation::axisChanged()
每当对象的轴发生变化时,都会发出此信号。
注意: 这是属性axis 的Notifier 信号。
另请参阅 QGraphicsRotation::axis 。
[signal] void QGraphicsRotation::originChanged()
每当源发生变化时,都会发出此信号。
注意: 这是属性origin的通知器 信号。
另请参阅 QGraphicsRotation::origin 。
void QGraphicsRotation::setAxis(Qt::Axis axis)
用于将坐标轴设置为axis 的便捷函数。
注意:对于QTransform ,Qt::YAxis 的旋转方向与三维空间中正确的数学旋转方向相反。QGraphicsRotation 类实现了正确的数学旋转。以下两段代码将执行相同的变换:
QTransform t;
t.rotate(45, Qt::YAxis);
QGraphicsRotation r;
r.setAxis(Qt::YAxis);
r.setAngle(-45);注意: 属性axis 的设置器 函数。
另请参阅 axis()。
© 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.