本页内容

QCustom3DItem Class

QCustom3DItem 类用于向图中添加自定义项目。更多内容...

头文件: #include <QCustom3DItem>
CMake: find_package(Qt6 REQUIRED COMPONENTS Graphs)
target_link_libraries(mytarget PRIVATE Qt6::Graphs)
qmake: QT += graphs
在 QML 中: Custom3DItem
继承自: QObject
被继承类:

QCustom3DLabel 以及QCustom3DVolume

属性

公共函数

QCustom3DItem(QObject *parent = nullptr)
QCustom3DItem(const QString &meshFile, QVector3D position, QVector3D scaling, const QQuaternion &rotation, const QImage &texture, QObject *parent = nullptr)
virtual ~QCustom3DItem() override
bool isPositionAbsolute() const
bool isRotationAbsolute() 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(QVector3D position)
void setPositionAbsolute(bool positionAbsolute)
void setRotation(const QQuaternion &rotation)
void setRotationAbsolute(bool rotationAbsolute)
void setRotationAxisAndAngle(QVector3D axis, float angle)
void setScaling(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(QVector3D position)
void rotationAbsoluteChanged(bool newRotationAbsolute)
void rotationChanged(const QQuaternion &rotation)
void scalingAbsoluteChanged(bool scalingAbsolute)
void scalingChanged(QVector3D scaling)
void shadowCastingChanged(bool shadowCasting)
void textureFileChanged(const QString &textureFile)
void visibleChanged(bool visible)

详细说明

自定义项具有自定义网格、位置、缩放、旋转以及可选的纹理。

另请参阅 Q3DGraphsWidgetItem::addCustomItem()。

属性文档

meshFile : QString

该属性存储物品网格文件的名称。

文件中的对象必须为网格格式。其他类型可通过Balsam资源导入工具进行转换。建议网格文件包含顶点、法线和 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(QVector3D position)

通知信号:

void positionChanged(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)

[since 6.11] rotationAbsolute : bool

该属性用于指定项目旋转应基于数据轴坐标还是绝对坐标进行处理。

定义项目旋转应基于数据值还是绝对值进行处理。默认值为true 。采用绝对旋转的项目将使用默认坐标进行旋转,无论轴向如何;而采用数据旋转的项目则将根据轴向坐标进行旋转。

该枚举在 Qt 6.11 中引入。

访问函数:

bool isRotationAbsolute() const
void setRotationAbsolute(bool rotationAbsolute)

通知信号:

void rotationAbsoluteChanged(bool newRotationAbsolute)

另请参阅 rotation 。

scaling : QVector3D

该属性将项目缩放率存储为QVector3D 。

默认值为QVector3D(0.1, 0.1, 0.1) 。

项的缩放采用数据值或绝对值,具体取决于scalingAbsolute 属性。默认向量被解释为绝对值,会将项设置为图表高度的10%,前提是项网格已归一化,且图表的宽高比未从默认值更改。

注意:在 Qt 6.8 中,模型默认被错误地假定为缩放至大小为 1(-0.5...0.5),而实际上它们是缩放至大小为 2(-1...1)。 因此,从 Qt 6.9 开始,所有自定义项的大小都是 Qt 6.8 的两倍

访问函数:

QVector3D scaling() const
void setScaling(QVector3D scaling)

通知器信号:

void scalingChanged(QVector3D scaling)

另请参阅 scalingAbsolute 。

scalingAbsolute : bool

此属性用于指定项目缩放应基于数据值还是绝对值进行处理。

默认值为true 。

采用绝对缩放的图元将始终以相同大小渲染,无论坐标轴范围如何。 采用数据缩放的项目将根据轴范围改变其显示大小。如果positionAbsolute 为true ,则此属性将被忽略,缩放将被解释为绝对值。如果项目进行了旋转,则数据缩放是基于未旋转的项目计算的。同样,对于QCustom3DVolume 项目,范围裁剪也是基于未旋转的项目计算的。

注意: 对于QCustom3DLabel 项或在polar 图表中使用的自定义项,仅 支持绝对缩放。

注意: 自定义项的网格 必须归一化到[-1 ,1] 范围内,否则数据缩放将不准确。

访问函数:

bool isScalingAbsolute() const
void setScalingAbsolute(bool scalingAbsolute)

通知器信号:

void scalingAbsoluteChanged(bool scalingAbsolute)

另请参阅 scaling 和positionAbsolute 。

shadowCasting : bool

该属性决定该物品是否启用投射阴影。

默认值为true 。如果false ,则无论Q3DGraphsWidgetItem::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, QVector3D position, QVector3D scaling, const QQuaternion &rotation, const QImage &texture, QObject *parent = nullptr)

使用指定的meshFile 、position 、scaling 、rotation 、texture 图像以及可选的parent ,构建一个自定义的3D对象。

[override virtual noexcept] QCustom3DItem::~QCustom3DItem()

删除自定义 3D 对象。

[invokable] void QCustom3DItem::setRotationAxisAndAngle(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.