QCustom3DItem Class
QCustom3DItem 类可在图形中添加自定义项。更多
Header: | #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) |
Notifier 信号:
void | positionChanged(const QVector3D &position) |
另请参阅 positionAbsolute 。
positionAbsolute : bool
该属性用于确定是以数据坐标还是绝对坐标处理项目位置。默认值为 。采用绝对坐标的项目将始终呈现,而采用数据坐标的项目只有在轴范围内才会呈现。
默认值为false
。使用绝对坐标的项目将始终呈现,而使用数据坐标的项目只有在轴范围内才会呈现。
访问功能:
bool | isPositionAbsolute() const |
void | setPositionAbsolute(bool positionAbsolute) |
Notifier 信号:
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) |
Notifier 信号:
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) |
Notifier 信号:
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 将被清除。
© 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.