Emilio
Emilio

Reputation: 4031

How can i make a Qt Quick (QML) ListView Item unselectable?

Can I make a QML Item contained into a ListView object unselectable? Something like this

 for(var i=0; i < ListView.model.count; i++) {                                                                                                         
       ListView.model.get(i).selectable = false;                                                                                         
 }      

Upvotes: 0

Views: 2253

Answers (1)

Paul Drummond
Paul Drummond

Reputation: 6073

If by "unselectable" you mean to prevent the user from being able to click on the item then you can add a selectable property to the model as you have done, then use it in the onClicked event in your ListView delegate - something like this:

ListView {
  ...
  delegate: Item {
    ....
    MouseArea {
      anchors.fill: parent;
      onClicked: {
        if(selectable) {
           //Do Something Interesting...
        } 
    }
  }
}

Also, it looks like you are referencing the model incorrectly. Either use the id of the ListView (e.g. myListView.model) or if your for loop is within scope you can refer to the model directly.

Upvotes: 1

Related Questions