Get index of the delegate currently displayed - QML ListView

前端 未结 4 967
无人共我
无人共我 2021-02-20 03:03

I created a ListView, which displays a couple of pages of content defined by the user (plain text). The page displayed is a delegate. Only one page is visible at a time. I decid

4条回答
  •  终归单人心
    2021-02-20 03:20

    You can use attached properties of ListView class (ListView). They are attached to each instance of the delegate.

    See ListView.isCurrentItem or ListView.view example:

    
        ListView {
            width: 180; height: 200
    
            Component {
                id: contactsDelegate
                Rectangle {
                    id: wrapper
                    width: 180
                    height: contactInfo.height
                    color: ListView.isCurrentItem ? "black" : "red"
                    Text {
                        id: contactInfo
                        text: name + ": " + number
                        color: wrapper.ListView.isCurrentItem ? "red" : "black"
                    }
                }
            }
    
            model: ContactModel {}
            delegate: contactsDelegate
            focus: true
        }
    
    

提交回复
热议问题