当时我一直在为此而努力。
Qt sQFileSystemModel
, 因为在计算几百份档案时确实很慢,因为icon fetching算法确实坏。
我想说的是完全可以置信的讽刺。 页: 1 QFileSystemModel:datameth which is not actual (the source of QFileSystemModel is available here:
This is the code I m trying to run:
class FileModel : public QFileSystemModel {
using QFileSystemModel::data;
public:
QVariant QFileSystemModel::data(const QModelIndex &index, int role) const
{
// my own implementation here
}
}
但它失败了。
<条码> 成员职能的定义 QFileSystemModel:data witin fileModel
<>>>>>
我设法压倒了这一职能,这是我现在的事情:
class FileModel : public QFileSystemModel {
public:
QVariant data(const QModelIndex &index, int role) const
{
// Here goes Qt s implementation
Q_D(const QFileSystemModel);
if (!index.isValid() || index.model() != this)
return QVariant();
switch (role) {
case Qt::EditRole:
case Qt::DisplayRole:
switch (index.column()) {
case 0: return d->name(index);
case 1: return d->size(index);
case 2: return d->type(index);
case 3: return d->time(index);
default:
qWarning("data: invalid display value column %d", index.column());
break;
}
break;
case FilePathRole:
return filePath(index);
case FileNameRole:
return d->name(index);
case Qt::DecorationRole:
if (index.column() == 0) {
QIcon icon = d->icon(index); // This is the part I need to change
if (icon.isNull()) {
if (d->node(index)->isDir())
icon = d->fileInfoGatherer.iconProvider()->icon(QFileIconProvider::Folder);
else
icon = d->fileInfoGatherer.iconProvider()->icon(QFileIconProvider::File);
}
return icon;
}
break;
case Qt::TextAlignmentRole:
if (index.column() == 1)
return Qt::AlignRight;
break;
case FilePermissions:
int p = permissions(index);
return p;
}
return QVariant();
}
};
However this code doesn t compile. This is the error I get:
const QFileSystemModelPrivate* QFileSystemModel::d_func() const is private