{
if (!d->indexValid(index))
if (role == Qt::DisplayRole || role == Qt::EditRole) {
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);
// you can return icons if the role == Qt::DecorationRole
//or else you can return icons if the role == Qt::DecorationRole and the index is in the column you want to present icons
default:
qWarning("data: invalid display value column %d", index.column());
}
}
if (index.column() == 0) {
if (role == FileIconRole)
return fileIcon(index);
if (role == FilePathRole)
return filePath(index);
if (role == FileNameRole)
return fileName(index);
}
if (index.column() == 1 && Qt::TextAlignmentRole == role) {
return Qt::AlignRight;
}
}
QVariant QDirModel::data(const QModelIndex &index, int role) const
{
Q_D(const QDirModel);
if (!d->indexValid(index))
return QVariant();
if (role == Qt::DisplayRole || role == Qt::EditRole) {
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);
// you can return icons if the role == Qt::DecorationRole
//or else you can return icons if the role == Qt::DecorationRole and the index is in the column you want to present icons
default:
qWarning("data: invalid display value column %d", index.column());
return QVariant();
}
}
if (index.column() == 0) {
if (role == FileIconRole)
return fileIcon(index);
if (role == FilePathRole)
return filePath(index);
if (role == FileNameRole)
return fileName(index);
}
if (index.column() == 1 && Qt::TextAlignmentRole == role) {
return Qt::AlignRight;
}
return QVariant();
}
To copy to clipboard, switch view to plain text mode
Bookmarks