How to load gif image in Qlistview
-
you still have to use QMovie but it's a bit more tricky.
You need to listen to QMovie's frameChanged() signal and trigger an update on the QListView using QAbstractItemView::update(const QModelIndex & index )
In your model return the current frame of QMovie in the data() method for Qt::DecorationRole. -
In your custom delegate do you call the base class implementation for painting or do you do the painting of the whole cell by yourself?
In the first case do as i said with the model and the Qt::DecorationRole. In the second case just paint the current frame of the QMovie yourself.
If you mean how to handle the QMovies:
You will need to store them on a central place (e.g. model) with your view. You can use QPersistentModelIndex for mapping the index to the right QMovie object.
But you need to take care of the cleanup of the list (or whatever storage container you use) and remove the QPersistentModelIndex and it's QMovie object from to avoid "infinite" memory consumption ;) -
then you just need to do this:
@
painter->drawPixmap( movie->currentPixmap() );
@since you connect to QMovie's frameChanged() signal as i said and trigger an update, the cell will be redrawn every time the gif animation image changes.
Thus you will see animated gifs in a listview.