Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Sort the System Drives in QTreeView using QSortFilterProxyModel
Stoned Jesus last edited by
I have a QTreeview where I am displaying all system drives using QFileSystemModel. I am looking for much better approach where a QTreeview can display Local Drives in one section, Removable Drive in another and so on. Basically sort the drives.
Here is the code:
@pSystemPrimaryModel = new QFileSystemModel(this);
pSystemPrimaryModel->setFilter( QDir::AllDirs | QDir::NoDotAndDotDot );
// Sets the model for the view to present.
// Just Display NAME and hide other Columns
for(int nCount = 1; nCount < pSystemPrimaryModel->columnCount(); nCount++)
This basically gives me all the drives as follows:
- New Volume(D:)
- New Volume(E:)
- Transcend Drive(G:) @
Using hideColumn() I have hidden all the header(Except Name) which gets displayed when QTreeView is used i.e. Name, Type, Size etc.
- What I basically want to achieve is this:
@+ Local Folder
- Removable Drives
Basically separate the local drives and external ones. I have come across QSortFilterProxyModel which looks like it sorts the drive order. But I have no clue how to use that.
- I want to remove the header in QTreeView. Since Name is visible in my output, I want to hide it. It would be helpful if you could guide me :)