QTableView+QFileSystemModel,修改item的图标

写一个新类继承QFileSystemModel,重写data函数:
QVariant QCustomFileSystemModel::data(const QModelIndex &index, int role) const
{
    if(role == Qt::DecorationRole)
    {
if(isDir(index)) { return QIcon(":/resource/Folder.png"); } else { return QIcon(":/resource/File.png"); } } return QFileSystemModel::data(index, role); }

把这个设为QTableView的model,则如果路径是文件夹,图标为Folder.png,否则为File.png

posted @ 2022-07-12 19:54  _KikyoBK  Views(286)  Comments(0Edit  收藏  举报