QCustom3DItem Class
QCustom3DItem 类可在图形中添加自定义项。更多
Header: | #include <QCustom3DItem> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Graphs) target_link_libraries(mytarget PRIVATE Qt6::Graphs) |
qmake: | QT += graphs |
在 QML 中: | Custom3DItem |
继承: | QObject |
继承于 |
- 所有成员(包括继承成员)的列表
- QCustom3DItem 是Qt Graphs C++ Classes for 3D 的一部分。
属性
|
|
公共功能
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 | 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 | 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 | 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) |
Notifier 信号:
void | positionChanged(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%,前提是项目网格已归一化,且图形纵横比未从默认值更改。
注: 在 Qt 6.8 中,模型被错误地假定为默认缩放为 1(-0.5...0.5),而实际上它们被缩放为 2(-1...1)。因此,从 Qt 6.9 开始,所有自定义项的大小都是 Qt 6.8 的两倍。
访问功能:
QVector3D | scaling() const |
void | setScaling(QVector3D scaling) |
Notifier 信号:
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) |
Notifier 信号:
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 将被清除。
© 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.