QGraphicsTransform Class
QGraphicsTransform 类是用于在 QGraphicsItem 上构建高级变换的抽象基类。更多内容...
| 头文件: | #include <QGraphicsTransform> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Widgets) target_link_libraries(mytarget PRIVATE Qt6::Widgets) |
| qmake: | QT += widgets |
| 继承自: | QObject |
| 继承自: |
公共函数
| QGraphicsTransform(QObject *parent = nullptr) | |
| virtual | ~QGraphicsTransform() |
| virtual void | applyTo(QMatrix4x4 *matrix) const = 0 |
受保护的槽
| void | update() |
详细说明
作为QGraphicsItem::transform 的替代方案,QGraphicsTransform允许您创建和控制高级变换,这些变换可通过专用属性进行独立配置。
QGraphicsItem 允许您将任意数量的 QGraphicsTransform 实例分配给一个QGraphicsItem 。每个 QGraphicsTransform 都会按顺序、一次一个地应用于其被分配的QGraphicsItem 。
QGraphicsTransform 在动画制作中尤为有用。虽然QGraphicsItem::setTransform() 允许您将任意变换直接分配给一个项目,但无法直接在两个不同的变换之间进行插值(例如,在两个状态之间过渡时,每个状态都为该项目分配了不同的任意变换)。 使用 QGraphicsTransform,您可以对每个独立变换的属性值进行插值。随后,将得到的操作组合成一个单一变换,并应用于QGraphicsItem 。
变换是在真正的 3D 空间中使用QMatrix4x4 计算的。当变换应用于QGraphicsItem 时,它将被投影回 2DQTransform 。 当多个 QGraphicsTransform 对象应用于QGraphicsItem 时,所有变换都在真正的 3D 空间中计算,只有在应用了最后一个 QGraphicsTransform 之后才会投影回 2D。QGraphicsRotation 是这一规则的例外,它会在每次旋转后投影回 2D,以保留围绕 X 轴和 Y 轴的透视效果。
若要创建自己的可配置变换,可以创建 QGraphicsTransform 的子类(或其任何现有子类),并重写纯虚函数applyTo(),该函数接受一个指向QMatrix4x4 的指针。 您希望应用的每项操作都应作为属性公开(例如:customTransform->setVerticalShear(2.5))。在您重写的applyTo()函数内部,可以相应地修改传入的变换。
QGraphicsTransform 可与QGraphicsItem::setTransform()、QGraphicsItem::setRotation() 和QGraphicsItem::setScale() 配合使用。
另请参阅 QGraphicsItem::transform()、QGraphicsScale 以及QGraphicsRotation 。
成员函数文档
QGraphicsTransform::QGraphicsTransform(QObject *parent = nullptr)
使用给定的parent 构建一个新的QGraphicsTransform。
[virtual noexcept] QGraphicsTransform::~QGraphicsTransform()
清除图形变换。
[pure virtual] void QGraphicsTransform::applyTo(QMatrix4x4 *matrix) const
这个纯虚拟方法必须在派生类中重新实现。
它将此转换应用于matrix 。
另请参阅 QGraphicsItem::transform() 和QMatrix4x4::toTransform()。
[protected slot] void QGraphicsTransform::update()
通知该变换操作已更改其参数,导致applyTo() 返回的结果与之前不同。
在实现自定义图形变换时,每次更改参数后都必须调用此函数,以告知 `QGraphicsItem ` 其变换需要更新。
另请参阅 applyTo()。
© 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.