QGraphicsTransform Class
QGraphicsTransform 类是一个抽象基类,用于在 QGraphicsItems 上构建高级转换。更多
头文件: | #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 允许您为一个 分配任意数量的 QGraphicsTransform 实例。每个 QGraphicsTransform 都会按顺序,一次一个地应用到分配给它的 。QGraphicsItem QGraphicsItem
QGraphicsTransform 对动画特别有用。QGraphicsItem::setTransform() 可让您直接为一个项目分配任意变换,但却没有在两个不同变换之间进行插值的直接方法(例如,在两个状态之间转换时,每个状态都为项目分配了不同的任意变换)。使用 QGraphicsTransform 可以对每个独立变换的属性值进行内插。由此产生的操作将合并为一个变换,应用于QGraphicsItem 。
变换是使用QMatrix4x4 在真实三维空间中计算的。当变换应用于QGraphicsItem 时,它将被投射回 2DQTransform 。当多个 QGraphicsTransform 对象应用于一个QGraphicsItem 时,所有变换都是在真三维空间中计算的,只有在应用最后一个 QGraphicsTransform 后才会投影回二维空间。但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()。
© 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.