I\'ve been struggling with this for some times now, and I can\'t seem to find the right way to do this.
What I would like is the ability to use an animated icon as a dec
One solution is to use QMovie with GIF. I also tried using SVG (it's lightweight and offers support for transparency), but both QMovie and QImageReader don't seem to support animated SVG.
Model::Model(QObject* parent) : QFileSystemModel(parent)
{
movie = new QMovie{ ":/resources/img/loading.gif" };
movie->setCacheMode(QMovie::CacheAll);
movie->start();
connect(movie, &QMovie::frameChanged,
[this] {
dataChanged(index(0, 0), index(rowCount(), 0),
QVector{QFileSystemModel::FileIconRole});
});
}
QVariant Model::data(const QModelIndex& index, int role) const
{
case QFileSystemModel::FileIconRole:
{
if (index.column() == 0) {
auto const path = QString{ index.data(QFileSystemModel::FilePathRole).toString() };
if (path.isBeingLoaded()){
return movie->currentImage();
}
}
}
}