QFileSystemModel custom icons?

前端 未结 2 486
情深已故
情深已故 2021-01-13 19:39

In my project, I have a QTreeView displaying a location on my drive. I need to change all the icons of the files to a custom icon but leave the folders alone.

I reim

2条回答
  •  自闭症患者
    2021-01-13 20:00

    Try to get filename and check is it a file or not. So it should be something like that:

    QVariant MyQFileSystemModel::data(const QModelIndex& index, int role) const
    {
        if(role == Qt::DecorationRole)
        {
            QString name = index.data();//get filename
            QFileInfo info(name);       
            if(info.isFile())           //check
                return QPixmap(":/icons/TAG_Int.png");//return image if file
        }
        return QFileSystemModel::data(index, role);   //if not, standard processing
    }
    

提交回复
热议问题