InstanceList QML Type
允许在 QML 中手动指定实例化。更多...
| Import Statement: | import QtQuick3D |
| Inherits: |
属性
- instanceCount : int
(since 6.3) - instances : List<QtQuick3D::InstanceListEntry>
详细说明
InstanceList 类型使得可以在 QML 中手动定义实例表。
以下示例创建了一个包含两个项的实例表:
InstanceList {
id: manualInstancing
instances: [
InstanceListEntry {
position: Qt.vector3d(0, 0, -60)
eulerRotation: Qt.vector3d(-10, 0, 30)
color: "red"
},
InstanceListEntry {
position: Qt.vector3d(50, 10, 100)
eulerRotation: Qt.vector3d(0, 180, 0)
color: "green"
}
]
}此外,还可以通过直接向 InstanceList 添加子元素来填充 instances 属性。以下示例与前一个示例效果相同:
InstanceList {
id: manualInstancing
InstanceListEntry {
position: Qt.vector3d(0, 0, -60)
eulerRotation: Qt.vector3d(-10, 0, 30)
color: "red"
}
InstanceListEntry {
position: Qt.vector3d(50, 10, 100)
eulerRotation: Qt.vector3d(0, 180, 0)
color: "green"
}
}每个 `InstanceListEntry ` 都是一个对象,可以拥有属性绑定和动画效果。这虽然提供了极大的灵活性,但也带来了内存开销。 因此,不建议将 InstanceList 用于包含数千(或数百万)个实例的程序化生成表格。此外,对任何条目的属性更改都会导致整个实例表被重新计算并上传至 GPU。
另请参阅 RandomInstancing 和QQuick3DInstancing 。
属性文档
instanceCount : int [since 6.3]
此只读属性包含列表中的实例数量。
该属性自 Qt 6.3 起引入。
instances : List<QtQuick3D::InstanceListEntry> [default]
该属性包含实例定义的列表。修改此列表或其中的任何元素,都会导致实例表被更新。
© 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.