1 Attachment(s)
Display System Drives in Specific Order in QTreeView
I have a treeview where I am displaying all system drives using QFileSystemModel. I am looking for much better approach where a tree view can display Local Drives in one section, Removable Drive in another and so on.
Here is the code:
Code:
pSystemPrimaryModel = new QFileSystemModel(this);
/* Sets the directory that is being watched by the model to currentPath by installing
a file system watcher on it. */
pSystemPrimaryModel
->setRootPath
(QDir::currentPath());
pSystemPrimaryModel
->setFilter
( QDir::AllDirs |
QDir::NoDotAndDotDot );
// Sets the model for the view to present.
ui->PrimTreeView->setModel(pSystemPrimaryModel);
// Regard less how many columns you can do this using for:
for(int nCount = nColCount; nCount < pSystemPrimaryModel->columnCount(); nCount++)
ui->PrimTreeView->hideColumn(nCount);
It gives me the following:
Attachment 8476
I want to display it like the second picture shown above. How can that be achieved?
Re: Display System Drives in Specific Order in QTreeView
Use a proxy model for sorting.
Re: Display System Drives in Specific Order in QTreeView
Quote:
Originally Posted by
wysota
Use a proxy model for sorting.
How do we do that? It will be helpful if you can guide me :)
Re: Display System Drives in Specific Order in QTreeView
Quote:
Originally Posted by
owais_blore
How do we do that? It will be helpful if you can guide me :)
QSortFilterProxyModel
Re: Display System Drives in Specific Order in QTreeView
Basically using this, i tried to play around and did something like this:
Code:
proxyModel->setSourceModel(pSystemPrimaryModel);
// Set the QStandardItemModel model of QTreeView to display audio and video files with details
ui->PrimTreeView->setModel(proxyModel);
it didnt work..... Looks like I have to use some functions
Re: Display System Drives in Specific Order in QTreeView
Since you want to change the order of the drives only, obviously just using a proxy that sorts *everything* will not work. You need to subclass it and reimplement the comparision method taking into consideration *what* you are sorting. And I have no idea why you used QStandardItemModel instead of QFileSystemModel in the last snippet. Maybe that's why it "didn't work" (whatever that means) :)
Re: Display System Drives in Specific Order in QTreeView
Well That was a typo from my side. I have used QFileSystemModel only. Looks like I have to re-implement the comparison method.
Quote:
Originally Posted by
wysota
Since you want to change the order of the drives only, obviously just using a proxy that sorts *everything* will not work. You need to subclass it and reimplement the comparision method taking into consideration *what* you are sorting. And I have no idea why you used
QStandardItemModel instead of
QFileSystemModel in the last snippet. Maybe that's why it "didn't work" (whatever that means) :)