开发者

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;                                                  开发者_StackOverflow社区                                       
 }      


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜