wrap it into a proxy model or subclass it
{
public:
ADirModel(...);
{
if (index.isValid() && role == Qt::DisplayRole)
{
if (rowCount(index)>0)
return QString("%1") (%2
)").arg(QDirModel::data(index).toString()).arg(rowCount(index); return QDirModel::data(index);
}
return QDirModel::data(index, role);
}
};
wrap it into a proxy model or subclass it
class ADirModel : public QDirModel
{
public:
ADirModel(...);
QVariant data(const QModelIndex &index, int role) const
{
if (index.isValid() && role == Qt::DisplayRole)
{
if (rowCount(index)>0)
return QString("%1") (%2)").arg(QDirModel::data(index).toString()).arg(rowCount(index);
return QDirModel::data(index);
}
return QDirModel::data(index, role);
}
};
To copy to clipboard, switch view to plain text mode
Untested. But something like that should work. The code assumes that only the first column has children and that this column is the one with the filename that should be extended.
(You might have to make some adjustments if you want the "(count)" in a different column.)
Also note that the use of rowCount() for the number of files is not quite correct:
subdirectories are counted as files, as would "." and ".." be.
But the example should get you going.
HTH
Bookmarks