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(Qt::Axis axis) |
void | setAxis(const QVector3D &axis) |
void | setOrigin(const QVector3D &point) |
重新实现的公共函数
virtual void | applyTo(QMatrix4x4 *matrix) const override |
信号
void | angleChanged() |
void | axisChanged() |
void | originChanged() |
详细说明
您可以通过为 axis 属性指定QVector3D 或将Qt::Axis 成员传递给setAxis 方便函数来提供所需的轴。默认情况下,坐标轴为 (0, 0, 1),即绕 Z 轴旋转。
由 QGraphicsRotation 提供的 angle 属性现在描述了围绕该轴旋转的度数。
QGraphicsRotation 提供了一些参数来帮助控制旋转的应用方式。
原点是项目围绕其旋转的点(即当项目的其他部分旋转时,原点相对于父项目保持固定)。默认情况下,原点为QPointF(0,0)。
角度属性提供了项目绕原点顺时针旋转的度数。该值也可以是负数,表示逆时针旋转。为了制作动画,提供超过 (-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) |
Notifier 信号:
void | angleChanged() |
另请参阅 原点。
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 的通知信号。
另请参见 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()。
© 2025 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.