[Qt-qml] How to access item in ListView delegate?

Juha Turunen turunen at iki.fi
Fri Sep 9 11:17:26 CEST 2011


On Fri, Sep 9, 2011 at 12:06 PM, Shawn <shawn at forevertrusts.com> wrote:
> Hi Riaan,
>
> Thank you for your suggestion, I add index attribute to the model, then
> it will work.

If all you need to do is compare the index to the currentIndex, you
don't need to define that index property. The ListView attaches a
boolean property to the instantiated delegate that indicates whether
the item is the current item. So you could get rid of that index
property by changing

 scale: (view.currentIndex == index) ? 1.2 : 1

to

 scale: ListView.isCurrentItem ? 1.2 : 1

Note that "ListView" isn't the id of the ListView element, but it's a
prefix for the name of the attached property. Here's a link to an
example in the official docs:
http://doc.qt.nokia.com/4.7-snapshot/qml-listview.html#isCurrentItem-prop

Juha


More information about the Qt-qml mailing list