QML - 如何使用GridView :: itemAt(真正的x,真实的y)?

时间:2018-02-20 09:51:26

标签: qt gridview qml

我可以像这样获得Repeater的项目:

var item = repeater.itemAt(index);

但是如何才能获得GridView的项目?我看到了itemAt function。但它与itemAt的{​​{1}}不同。它需要Repeaterx坐标,但我们可以使用y中的索引,例如GridView。我该如何访问该项目?

修改:

Repeater

我总是看到gridView.currentIndex = index; var a = gridView.currentItem; gridView.currentIndex = lastIndex; var b = gridView.currentItem; if (a.imageSource === b.imageSource) console.log('Equals!'); 输出。但是它们(图像)不等于(a有1.png,b有2.png)。

1 个答案:

答案 0 :(得分:1)

似乎没有功能的构建,但你可以尝试这种方法:

gridView.currentIndex = index; // your index
var item = gridView.currentItem;

// reset the current index to the previous value if you have to

也许这也会起作用(未经测试):

var item = gridView.children[index];

这更像是一种解决方法,但应该适用于你的情况。