Get index of the delegate currently displayed - QML ListView

前端 未结 4 1020
无人共我
无人共我 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:24

    I know this is quite old but I had the same problem and spend some time trying to find a way to get currentIndex that would work for me. In my case sometimes I need to change the width of my ListView so I have to recalculte currentIndex manualy every time I resize it.

    But I found a highlightRangeMode property. When it's set to ListView.StrictlyEnforceRange then currentIndex is always updated automaticly and contains correct index of the currently visible item.

    ListView {
        highlightRangeMode: ListView.StrictlyEnforceRange 
        // ...
    }
    

提交回复
热议问题