Custom icons for QFileSystemModel
-
Hi ,
I was wondering if anybody knew of a way to use custom icons the file system uses to show your files/folders....The Doc has pointed me to QFileIconProvider but i did not find anyway to match "QFileIconProvider::IconType":http://qt-project.org/doc/qt-5.1/qtwidgets/qfileiconprovider.html#IconType-enum to the custom icons of my choosing.Any help would be appreciated.
-
subclass QFileSystemModel and reimplement data() method. The following should do what you want:
@
QVariant MyFileModel::data ( const QModelIndex & index, int role ) const
{
if( index.column() == 0 && role == Qt::DecorationRole )
//you may want to check "index.data().toString()" for the file-name/-extension
return QVariant::fromValue(icon);
else
return QFileSystemModel::data(index, role);
}
@ -
alternatively you can also subclass QFileIconProvider as you already mentioned and reimplement all virtual methods. And set the file icon provider class with QFileSystemModel::setIconProvider(yourIconProvider).
[quote author="musimbate" date="1375257223"]Hi ,
but i did not find anyway to match "QFileIconProvider::IconType":http://qt-project.org/doc/qt-5.1/qtwidgets/qfileiconprovider.html#IconType-enum to the custom icons of my choosing.[/quote]
What exactly do you mean? -
Thanks raven-worx for the reply.
[quote author="raven-worx" date="1375263368"]
What exactly do you mean?
[/quote]I thought I could use QFileInfoProvider to set the icons that QFileSystemModel uses to show the icons for files/folders.If this could be done there should be some kind of setIcon()/setIcons() function to set them right?
May be I am getting wrong the intended usage of QFileInfoProvider.
-
i haven't looked into the sources of QFileSystemModel yet, but i would bet that it queries the icon from the QFileIconProvider in it's data() method implementation for the decoration role. (In the way like i stated it in the code before)