带有 id 的 Qml 中继器 [英] Qml Repeater with ids

查看:19
本文介绍了带有 id 的 Qml 中继器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果写了如下代码:

Repeater { model: 10; 
delegate: Rectangle { width: 200; height:           
20; color: "white";}}

如何为所有 10 个矩形赋予不同的 id?

How can I give all the 10 rectangles a different id?

推荐答案

你不能分配不同的id,而且id有一个范围,其限制是delegate,如果你想访问一个项目你必须使用itemAt() 方法传递索引:

You can not assign a different id, also the id has a scope whose limit is the delegate, if you want to access an item you must use the itemAt() method passing the index:

Repeater { 
    id: repeater
    model: 10; 
    delegate: Rectangle { 
        width: 200; 
        height: 20; 
        color: "white";
    }
}

// ...

var item = repeater.itemAt(2)

这篇关于带有 id 的 Qml 中继器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆