How to take index of element StackView in QML ?
-
Hi and welcome to devnet,
Isn't the StackView Finding Items Chapter what you are looking for ?
-
Hi @mrbongdem
Also in addition to @SGaist's answerStackView
too has a few attached properties andindex
is one of them. Check supported-attached-properties. -
@mrbongdem Thats great. But how did you use
ListModel
withStackView
? You can directly get index usingStack.index
inside the item without creating a new property. -
Hi @p3c0
I use this way :StackView { id: stackView initialItem: ListView { model: rssFeeds delegate: Button{ onClicked: { // at here I take index .It is property of ListModel rssFeeds } } } }
And How do you use Stack.index .Can you give me example for it ?
Thank you for your replay. -
@mrbongdem Ok so you have
StackView
which containsListView
in which you wantedindex
. I imagined something different from your original question.
AnywayListView
hasindex
attached property. So no need of creating another index property. Eg.ListView { model: ListModel { Component.onCompleted: { for(var a=10; a<15; a++) append( { name: "Item: " + a }) } } delegate: Text { text: name + " with Index: " + index //index = attached property } }