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. QAbstractListModel subclass removeRows and transition animations

QAbstractListModel subclass removeRows and transition animations

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 434 Views 1 Watching
  • 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.
  • E Offline
    E Offline
    Eventh
    wrote on last edited by Eventh
    #1

    Okay, so I have a QAbstractListModel subclass and am trying to remove rows and have an opacity remove transition on the listview on the QML side.
    My remove function looks something like this...

    void Model::RemoveRows()
    {
       for ( auto i = itemsInModel.size() - 1; i >= 0; i-- )
       {
          auto it = std::find_if( std::begin( allItems ), std::end( allItems ),
                           [ & ]( const Item& item){ return item.name == itemsInModel.at( i ).name; } );
    
          if ( !itemsInModel.at( i ).name.contains( filter ) || it == std::end( allItems ) )
             RemoveRow( i );
       }
    }
    

    And RemoveRow looks like:

    void Model::RemoveRow( int index )
    {
       beginRemoveRows( QModelIndex(), index, index );
    
       itemsInModel.removeAt( index );
    
       endRemoveRows();
    }
    

    I have a simple remove transition attached to a ListView that this model is attached to. For some reason say if there is 5 items in the model and I remove index 2 and index 0 then the items get removed, shuffled in the list, and then the transition animation plays on the newly shuffled items instead of the old items. The list just gets shorter and then the animation plays on items 1 and 3 (which are now in indices 0 and 2 respectively). Just curious if I am doing something wrong or whatnot. Thanks in advance!

    Oh and my listview looks something like:

      ListView
      {
         id: listView
    
         height: Math.min( contentHeight, maxListHeight )
         model: myCPPModel
         clip: true
    
         add: Transition{ NumberAnimation{ property: "opacity"; from: 0; to: 1; duration: 500 } }
         addDisplaced: Transition{ NumberAnimation{ property: "opacity"; to: 1 } }
    
         remove: Transition{ NumberAnimation{ property: "opacity"; from: 1; to: 0; duration: 500 } }
         removeDisplaced: Transition{ NumberAnimation{ property: "opacity"; from: 1; to: 0 } }
    
         delegate: Text{ text: myText }
      }
    
    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