PDA

View Full Version : Sort System Drives via QSortFilterProxyModel



owais_blore
6th December 2012, 07:42
I just want to know which function of QSortFilterProxyModel class is used to sort the local and removable drives in system. Basically I am working on a app where I am using treeview and I need to sort them in a order.

Here is the code:

pSystemPrimaryModel = new QFileSystemModel(this);
pSystemPrimaryModel->setRootPath(QDir::currentPath());

QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this);
proxyModel->setSourceModel(pSystemPrimaryModel);
proxyModel->setDynamicSortFilter(false);

// Set the QFileSystemModel model of QTreeView to display drives
ui->PrimTreeView->setModel(proxyModel);
This displays drives in a regular manner as follows:

+ C:
+ New Volume(D:)
+ New Volume(E:)
+ SD_Card(F:)
+ Transcend Drive(G:
Basically I want to display it like follows:

+ Local Folder
+ C:
+ New Volume(D:)
+ New Volume(E:)
+ Removable Drives
+ SD_Card(F:)
+ Transcend Drive(G:)

anda_skoa
6th December 2012, 20:10
QSortFilterProxyModel can only change the order to things or remove things, it can't be used to add a whole level into the three.

I guess you'll have to write your own proxy model that can add this on top of the structure and data provided by the file system model

Cheers,
_

owais_blore
7th December 2012, 07:08
Thanks Anda. I have been looking at it for sometime but not finding any info. It looks easy but its complicated. Any further help???


QSortFilterProxyModel can only change the order to things or remove things, it can't be used to add a whole level into the three.

I guess you'll have to write your own proxy model that can add this on top of the structure and data provided by the file system model

Cheers,
_

anda_skoa
8th December 2012, 21:05
Yeah, unfortunately manipulating the structure in a proxy model is not that easy.

I would suggest that you try to implement a simple tree model yourself first as to get a hang on how the model indexes work in tree structures.

Like starting with a list model (subclass QAbstractListModel) and once you fnd yourself comfortable with that try an QAbstractItemModel subclass.

Cheers,
_