Repeater3D QML Type
使用提供的模型实例化若干基于节点的组件。更多
| Import Statement: | import QtQuick3D |
| Inherits: | |
| Inherited By: |
属性
- count : int
- delegate : Component
- delegateModelAccess : enumeration
(since 6.10) - model : any
信号
- objectAdded(int index, Object3D object)
- objectRemoved(int index, Object3D object)
方法
- Object3D objectAt(index)
详细说明
Repeater3D 类型用于创建大量类似的项目。与其他视图类型一样,Repeater3D 也有一个model 和一个delegate :对于模型中的每个条目,委托都会在使用模型数据种子的上下文中实例化。
Repeater 的model 可以是任何支持的数据模型。此外,与其他视图的委托一样,中继器委托可以访问其在中继器中的索引以及与委托相关的模型数据。有关详情,请参阅delegate 属性文档。
注: Repeater3D 项目拥有其实例化的所有项目。删除或动态销毁 Repeater3D 创建的项目会导致不可预测的行为。
属性文档
count : int [read-only]
此属性表示模型中的项目数。
注意: 如果Repeater3D 正在实例化委托或设置不正确,则 count 所报告的模型中的项目数可能与创建的委托数不同。
delegate : Component [default]
委托提供了一个模板,定义了中继器实例化的每个对象。
代表暴露于一个只读的index 属性,该属性表示代表在中继器中的索引。
如果model 是一个模型对象(如ListModel ),委托就能以命名属性的方式访问所有模型角色,就像委托访问视图类(如ListView )一样。
另请参阅 QML 数据模型。
delegateModelAccess : enumeration [since 6.10]
该属性决定了代表如何访问模型。
| 常数 | 说明 |
|---|---|
DelegateModel.ReadOnly | 禁止代表通过上下文属性、model 对象或必填属性写入模型。 |
DelegateModel.ReadWrite | 允许代表通过上下文属性、model 对象或必填属性写入模型。 |
DelegateModel.Qt5ReadWrite | 允许代表通过model 对象和上下文属性写入模型,但不允许通过必填属性写入模型。 |
默认值为DelegateModel.Qt5ReadWrite 。
此属性在 Qt 6.10 中引入。
另请参阅 Qt Quick#更改模型数据中的模型和视图。
model : any
为中继器提供数据的模型。
该属性可设置为任何支持的数据模型:
- 一个数字,表示中继器要创建的代表数目
- 模型(例如ListModel 项目或QAbstractItemModel 子类)
- 字符串列表
- 对象列表
模型的类型会影响delegate 所显示的属性。
另请参阅 数据模型。
信号文档
objectAdded(int index, Object3D object)
当一个对象被添加到中继器时,就会发出该信号。index 参数包含对象插入中继器的索引,object 参数包含已添加的Object3D 。
相应的处理程序是onObjectAdded 。
注: 相应的处理程序是onObjectAdded 。
objectRemoved(int index, Object3D object)
当一个对象从中继器中移除时,就会发出该信号。index 参数包含项目从中继器中移除时的索引,而object 参数则包含被移除的Object3D 。
如果object 是由该中继器创建的,则不要保留对它的引用,因为在这种情况下,它将在信号处理后不久被删除。
相应的处理程序是onObjectRemoved 。
注: 相应的处理程序是onObjectRemoved 。
方法文档
Object3D objectAt(index)
返回在给定的index 上创建的Object3D ,如果index 上不存在项目,则返回null 。
© 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.