QML ListView 等view的使用

每个委托都可以拥有独立的MouseArea以及Key处理机构

Component {
        id:featureButtonsDelegate
        Rectangle
        {
            property bool pressed: false;
            id:wrapper;
            width: wrapper.ListView.view.width;
            height: Math.max(wrapper.ListView.view.height/wrapper.ListView.view.model.count,40);
            color: "lightblue";
            border.width: 0;
            Text {
                id: text
                anchors.centerIn: parent;
                text: model.name;
            }

            MouseArea {
                anchors.fill: parent;
                onClicked: {
                    root.sigItemClicked(text.text,pressed);
                    for(var i=0;i<wrapper.ListView.count;i ++) {
                        if(i!=index) {
                            
                        }
                    }
                }
            }

            states: [
                State {
                    name: "pressed"; when: wrapper===true;
                    PropertyChanges {
                        target: wrapper;
                        color: "deepskyblue";
                    }
                }
            ]
            transitions: [
                Transition {
                    ColorAnimation { target: wrapper; duration: 200; }
                }
            ]
        }
    }


当某个委托被点击之后设置为当前view的当前项目

  1. MouseArea {
  2.     anchors. fill : parent
  3.     onClicked : {
  4.         listView. currentIndex = index
  5.     }
  6. }


count 属性:

指明view中有多个item,并不仅仅局限于当前显示出来的item,所有的可供显示的item的数目.

你可能感兴趣的:(QML ListView 等view的使用)