Congratulations to our 2022 Qt Champions!

ListView and onCurrentIndexChanged

  • Hi everyone. I have a ListView

    @ ListView{
    anchors.fill: parent

        currentIndex: 0
        onCurrentIndexChanged: root.currentIndex = currentIndex
        orientation: Qt.Horizontal
        boundsBehavior: Flickable.DragOverBounds
        model: someModel
        highlightRangeMode: ListView.StrictlyEnforceRange
        snapMode: ListView.SnapOneItem

    the index is changed when the second item is at half of the ListView screen. Can I make it change only when the second item is entirely visible to the screen??

  • You could only set root.currentIndex once the view has stopped moving:

    @ onCurrentIndexChanged: if (!moving) root.currentIndex = currentIndex
    onMovingChanged: if (!moving) root.currentIndex = currentIndex@

Log in to reply