QFileSystemModel has three additional "user roles" to retrieve the file name, path, and permissions. I guess that when you use an "off the shelf" QFileSystemModel, it will give a column count of 4 and serve up the fields you are seeing.
Others may know of a better way, but my implementation would be to derive from QFileSystemModel and modify the columnCount(), headerData(), and data() methods to add the extra column. In the data method, when asked for the DisplayRole for the column you have designated as the Path column, the custom model returns this:
int MyFileSystemModel
::columnCount( const QModelIndex & index
) const {
return QFileSystemModel::columnCount( index ) + 1;
}
QVariant MyFileSystemModel
::headerData( int section, Qt
::Orientation o,
int role
) {
if ( o == Qt::Horizontal && section == pathColumn )
{
if ( role == Qt::DisplayRole )
else
}
else
return QFileSystemModel::headerData( section, o, role );
}
{
if ( index.column() == pathColumn ) // your member or static variable denoting the path column number
{
if ( role == Qt::DisplayRole )
return QFileSystemModel::data( index, QFileSystemModel::FilePathRole );
else
}
else
return QFileSystemModel::data( index, role );
}
int MyFileSystemModel::columnCount( const QModelIndex & index ) const
{
return QFileSystemModel::columnCount( index ) + 1;
}
QVariant MyFileSystemModel::headerData( int section, Qt::Orientation o, int role )
{
if ( o == Qt::Horizontal && section == pathColumn )
{
if ( role == Qt::DisplayRole )
return QVariant( "Path" );
else
return QVariant();
}
else
return QFileSystemModel::headerData( section, o, role );
}
QVariant MyFileSystemModel::data( const QModelIndex & index, int role ) const
{
if ( index.column() == pathColumn ) // your member or static variable denoting the path column number
{
if ( role == Qt::DisplayRole )
return QFileSystemModel::data( index, QFileSystemModel::FilePathRole );
else
return QVariant();
}
else
return QFileSystemModel::data( index, role );
}
To copy to clipboard, switch view to plain text mode
(Untested, might require tweaking).
Bookmarks