Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Listview add-animation with scrolling
Forum Updated to NodeBB v4.3 + New Features

Listview add-animation with scrolling

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tobias F
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved