在我的项目中,我有一个 QTreeView 显示我的驱动器上的位置。我需要将文件的所有图标更改为自定义图标,但保留文件夹。
我重新实现了 QFileSystemModel 并且能够更改所有图标。有什么方法可以限制仅更改文件而不是文件夹吗?
QVariant MyQFileSystemModel::data(const QModelIndex& index, int role) const
{
if(role == Qt::DecorationRole)
return QPixmap(":/icons/TAG_Int.png");
return QFileSystemModel::data(index, role);
}
Run Code Online (Sandbox Code Playgroud)
这:

变成:

如何只更改文件的图标?
谢谢你的时间 :)