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