AliReza
AliReza

Reputation: 75

How can I get the roles of a few currentItem from a listview in qml?

How can I get the roles of a few currentItem from a listview in qml?

Something like:

ListView {
    id: listview
    model: myModel
    delegate: Item {
        property variant myData: model
        Text {
            text: model.text
        }
        Text {
            text: model.moreText
        }
    }
    onCurrentIndexChanged:{
        listview.currentItem[currentIndex].myData.text
        listview.currentItem[currentIndex + 1].myData.text
        listview.currentItem[currentIndex + 2].myData.text
    }
}

Upvotes: 2

Views: 1479

Answers (3)

GrecKo
GrecKo

Reputation: 7160

If you know the role indexes of your model you could do myModel.data(myModel.index(currentIndex, 0), roleIndex)

Upvotes: 0

derM
derM

Reputation: 13701

From a few currentItem? Isn't currentItem singular?
currentItem points to a currently selected Item and is not a list of Items.

Maybe you want to have this:

myModel.get(currentIndex + i).myRole

Upvotes: 1

Robin Burchell
Robin Burchell

Reputation: 881

There's not really a good "generic" way to do this at this time, so the answer depends on your model type. If you are using ListModel for instance, you can use ListModel::get. If you are using a C++ model, I'd recommend taking a look at the answers on this question.

Upvotes: 2

Related Questions