PDA

View Full Version : Display Filesystem Using QFileSystemModel & QStandardItemModel



owais_blore
7th December 2012, 09:12
I had asked the question about displaying Filesystem inside a treeview in such a way where local drives and removable drive get displayed under a root node - Local Drivess & Removable Drives.


QStandardItemModel *m_model = new QStandardItemModel(0,0);
pSystemPrimaryModel = new QFileSystemModel(this);
pSystemPrimaryModel->setRootPath(QDir::currentPath());
pSystemPrimaryModel->setFilter( QDir::AllDirs | QDir::NoDotAndDotDot );

QList<QStandardItem *> LocalItem;
LocalItem.insert(0,new QStandardItem("Local Drives"));
LocalItem.at(0)->setEditable(false);
m_model->insertRow(0,LocalItem);

QStandardItem* Localchild = new QStandardItem();
QStandardItem* LocalparentItem = m_model->item(0,0);
LocalparentItem->appendRow(Localchild);

ui->PrimTreeView->setModel(m_model);
This displays output with only Local Drives and no drives under it since I am not setting pSystemPrimaryModel in setModel.
8483
I wanna display the drives which are shown towards the bottom side of image under this "Local Drives" node which QFileSystemModel displays when used like this:

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

owais_blore
7th December 2012, 13:29
Anyone here who can help me???

wysota
8th December 2012, 17:36
And what is the question?

airglide
8th December 2012, 19:53
If I'm right you want to combine QFileSystemModel and QStandardItemModel in one model and then display it in a treeview?

Then I'd sugegst using a QAbstractProxyModel, wysota correct me if I'm wrong, haven't dealt with that so much:)

wysota
9th December 2012, 00:20
Then I'd sugegst using a QAbstractProxyModel, wysota correct me if I'm wrong, haven't dealt with that so much:)

Hard to say. I'm wondering if it's not going to be easier to create a new model from scratch. The problem with proxy models is that it is quite hard to implement a hierarchical proxy model if one is not used to the technology.

owais_blore
10th December 2012, 06:48
Then which is a better approach??? I tried a lot and everytime it seems to just give the same result. I googled a lot and i am surprised nobody has come across this scenario..... what has to be done?


Hard to say. I'm wondering if it's not going to be easier to create a new model from scratch. The problem with proxy models is that it is quite hard to implement a hierarchical proxy model if one is not used to the technology.

wysota
10th December 2012, 11:15
Then which is a better approach??? I tried a lot and everytime it seems to just give the same result. I googled a lot and i am surprised nobody has come across this scenario..... what has to be done?

To be honest we have no idea what you tried. I'm almost sure there is no "how to add another level of nodes to the filesystem model" tutorial available so you have to go past tutorials and do some thinking of your own. I would probably try some combined approach like having a custom model for the top nodes and attaching filesystem models for the nodes I need. But then I have some quite deep knowledge of how models work in Qt. I think building a model from scratch that is dynamically filled with data using canFetchMore() is also an option. But again this requires something more than just reading one or two tutorials.