Listview add-animation with scrolling



  • Hi all,

    I've a listview bound to a C++-Model that implements a class inherited from QAbstractListModel.
    The Listview is defined in QML in the following way

    ListView {
            anchors.fill: parent
            model: $viewModel
            add: Transition {
                PropertyAnimation {
                    duration: 1000
                    properties: "height"
                    from: 0
                    to: 100
                }
            }
            delegate: Item {
                width: 600
                height: 100
                Text {
                    id: name
                    text: model.display.name
                }
                Rectangle {
                    anchors.bottom: parent.bottom
                    width: 600
                    height: 2
                    color: "black"
                }
    
                MouseArea {
                    anchors.fill: parent
                    onClicked: $viewModel.insertBefore(index)
                }
            }
        }
    

    Now what I wan't to achieve is that I click for example the 4the item of the ListView and a new item is added in the C++-Model at the 4th position and therewith before the clicked item. That is already working through the $viewModel.insertBefore(index) call, but now comes the tricky part. I want to keep the position of the clicked item and animate the height of the added item. With the PropertyAnimation specified for the Add-Transition the inserted item is animated but the clicked-item is moved to the bottom during the animation. How could I achieve that the clicked item stays at the position before the click and the animation moves the top item away.
    Is there something I can do with currentItem, preferredHighlightBegin, preferredHighlightEnd to achieve the desired behaviour, or is there any other way to do this?

    Thanks a lot


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.