开发者

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

开发者 https://www.devze.com 2023-04-10 23:00 出处:网络
Can I make a QML Item contained into a ListView object unselectable? Something like this for(var i=0; i < ListView.model.count; i++) {

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

精彩评论

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

关注公众号