QCustom3DItem Class
QCustom3DItem 类用于向图中添加自定义项目。更多内容...
| 头文件: | #include <QCustom3DItem> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS DataVisualization) target_link_libraries(mytarget PRIVATE Qt6::DataVisualization) |
| qmake: | QT += datavisualization |
| 自: | QtDataVisualization 1.1 |
| 在 QML 中: | Custom3DItem |
| 继承自: | QObject |
| 被继承自: | |
| 状态: | 已弃用 |
该类已弃用。我们强烈建议不要在新代码中使用它。
属性
|
|
公共函数
| QCustom3DItem(QObject *parent = nullptr) | |
| QCustom3DItem(const QString &meshFile, const QVector3D &position, const QVector3D &scaling, const QQuaternion &rotation, const QImage &texture, QObject *parent = nullptr) | |
| virtual | ~QCustom3DItem() |
| bool | isPositionAbsolute() const |
| bool | isScalingAbsolute() const |
| bool | isShadowCasting() const |
| bool | isVisible() const |
| QString | meshFile() const |
| QVector3D | position() const |
| QQuaternion | rotation() |
| QVector3D | scaling() const |
| void | setMeshFile(const QString &meshFile) |
| void | setPosition(const QVector3D &position) |
| void | setPositionAbsolute(bool positionAbsolute) |
| void | setRotation(const QQuaternion &rotation) |
| void | setRotationAxisAndAngle(const QVector3D &axis, float angle) |
| void | setScaling(const QVector3D &scaling) |
| void | setScalingAbsolute(bool scalingAbsolute) |
| void | setShadowCasting(bool enabled) |
| void | setTextureFile(const QString &textureFile) |
| void | setTextureImage(const QImage &textureImage) |
| void | setVisible(bool visible) |
| QString | textureFile() const |
信号
| void | meshFileChanged(const QString &meshFile) |
| void | positionAbsoluteChanged(bool positionAbsolute) |
| void | positionChanged(const QVector3D &position) |
| void | rotationChanged(const QQuaternion &rotation) |
| void | scalingAbsoluteChanged(bool scalingAbsolute) |
| void | scalingChanged(const QVector3D &scaling) |
| void | shadowCastingChanged(bool shadowCasting) |
| void | textureFileChanged(const QString &textureFile) |
| void | visibleChanged(bool visible) |
另请参阅 QAbstract3DGraph::addCustomItem()。
属性文档
meshFile : QString
该属性存储对象的网格文件名。
文件中的对象必须为 Wavefront OBJ 格式,并包含顶点、法线和 UV 坐标。此外,该对象必须由三角面组成。如果文件缺少法线或 UV 坐标,加载将失败,控制台会输出错误信息,且该对象将无法渲染。
访问函数:
| QString | meshFile() const |
| void | setMeshFile(const QString &meshFile) |
通知信号:
| void | meshFileChanged(const QString &meshFile) |
position : QVector3D
该属性将项目位置存储为QVector3D 。
默认值为QVector3D(0.0, 0.0, 0.0) 。
项目位置可通过数据坐标或绝对坐标指定,具体取决于positionAbsolute 属性。使用绝对坐标时,-1.0...1.0 之间的值属于轴范围。
注意: 若positionAbsolute 为false ,且项目 位置超出任何轴范围,则该项目 不会被渲染;除非该项目是QCustom3DVolume(此时其部分可见),且scalingAbsolute 同时为false 。在这种情况下,体积的可见部分将被渲染。
访问函数:
| QVector3D | position() const |
| void | setPosition(const QVector3D &position) |
通知器信号:
| void | positionChanged(const QVector3D &position) |
另请参阅 positionAbsolute 。
positionAbsolute : bool
该属性决定了项目位置是采用数据坐标还是绝对坐标进行处理。
默认值为false 。采用绝对坐标的项将始终被渲染,而采用数据坐标的项仅在位于轴范围之内时才会被渲染。
访问函数:
| bool | isPositionAbsolute() const |
| void | setPositionAbsolute(bool positionAbsolute) |
通知器信号:
| void | positionAbsoluteChanged(bool positionAbsolute) |
另请参阅 position 。
rotation : QQuaternion
该属性将项目的旋转角度存储为QQuaternion 。
默认值为QQuaternion(0.0, 0.0, 0.0, 0.0) 。
访问函数:
| QQuaternion | rotation() |
| void | setRotation(const QQuaternion &rotation) |
通知信号:
| void | rotationChanged(const QQuaternion &rotation) |
scaling : QVector3D
该属性将项目缩放值作为QVector3D 存储。
默认值为QVector3D(0.1, 0.1, 0.1) 。
项目缩放采用数据值或绝对值,具体取决于scalingAbsolute 属性。默认向量被解释为绝对值时,会将项目设置为图表高度的10%——前提是项目网格已归一化,且图表的宽高比未偏离默认值。
访问函数:
| QVector3D | scaling() const |
| void | setScaling(const QVector3D &scaling) |
通知信号:
| void | scalingChanged(const QVector3D &scaling) |
另请参阅 scalingAbsolute 。
[since QtDataVisualization 1.2] scalingAbsolute : bool
此属性用于指定项目缩放应基于数据值还是绝对值进行处理。
默认值为true 。
采用绝对缩放的元素将以相同大小渲染,无论坐标轴范围如何。 采用数据缩放的项将根据坐标轴范围改变其显示大小。如果positionAbsolute 为true ,则此属性将被忽略,缩放将被解释为绝对值。如果项进行了旋转,则数据缩放是基于未旋转的项计算的。同样,对于 QCustom3DVolume 项,范围裁剪也是基于未旋转的项计算的。
注意: 对于 QCustom3DLabel 项目或用于polar 图表的自定义项目,仅 支持绝对缩放。
注意: 自定义项的网格 必须归一化到[-1 ,1] 范围内,否则数据缩放将不准确。
此枚举在 QtDataVisualization 1.2 中引入。
访问函数:
| bool | isScalingAbsolute() const |
| void | setScalingAbsolute(bool scalingAbsolute) |
通知器信号:
| void | scalingAbsoluteChanged(bool scalingAbsolute) |
另请参阅 scaling 和positionAbsolute 。
shadowCasting : bool
该属性控制该项是否启用投射阴影。
默认值为true 。如果false ,则无论QAbstract3DGraph::ShadowQuality 的设置如何,该项都不会投射阴影。
访问函数:
| bool | isShadowCasting() const |
| void | setShadowCasting(bool enabled) |
通知信号:
| void | shadowCastingChanged(bool shadowCasting) |
textureFile : QString
该属性存储了该项的纹理文件名。
如果此属性与纹理图像均未设置,则将使用纯灰色纹理。
注意:为 节省内存,从文件加载的QImage 在纹理创建完成后将被清空。
访问函数:
| QString | textureFile() const |
| void | setTextureFile(const QString &textureFile) |
通知器信号:
| void | textureFileChanged(const QString &textureFile) |
visible : bool
该属性用于存储该项的可见性。
默认值为true 。
访问函数:
| bool | isVisible() const |
| void | setVisible(bool visible) |
通知器信号:
| void | visibleChanged(bool visible) |
成员函数文档
[explicit] QCustom3DItem::QCustom3DItem(QObject *parent = nullptr)
使用指定的parent 构建一个自定义的3D对象。
[explicit] QCustom3DItem::QCustom3DItem(const QString &meshFile, const QVector3D &position, const QVector3D &scaling, const QQuaternion &rotation, const QImage &texture, QObject *parent = nullptr)
使用指定的meshFile 、position 、scaling 、rotation 、texture 图像以及可选的parent ,构建一个自定义的3D项目。
[virtual noexcept] QCustom3DItem::~QCustom3DItem()
删除自定义 3D 对象。
[invokable] void QCustom3DItem::setRotationAxisAndAngle(const QVector3D &axis, float angle)
一个便捷函数,用于根据axis 和angle 构建旋转四元数。
注意:此 函数可通过元对象系统及 QML 调用。参见Q_INVOKABLE 。
另请参阅 rotation 。
void QCustom3DItem::setTextureImage(const QImage &textureImage)
将textureImage 的值设置为该项的QImage 。纹理默认显示为纯灰色。
注意:为 节省内存,在创建纹理后,给定的QImage 将被清空。
© 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.