PDA

View Full Version : QFileSystemModel root



Alundra
9th June 2014, 05:11
Hi all,
Using a QFileSystemModel you never have the root item showed.
When you use it for an explorer it's impossible to go back at the root.
Does a way exists to show the root item ?
Is it possible to use multiple QFileSystemModel in one model to show multiple folder ?
To have a correct result the root of each folder should be shown.
Thanks for the help

wysota
9th June 2014, 08:56
By definition a root index of the view is the index whose children are shown in the view. This is the same for the file system model -- a root is a directory whose children are to be represented in the model. If you want to see the current root directory as well then either change the root of the model to the parent directory or wrap the model in a custom proxy model that will return a modified model structure.

Alundra
9th June 2014, 12:44
I tried :


ListTreeModel->setRootPath( QDir::currentPath() );
m_ListTree->setRootIndex( ListTreeModel->index( "Content/" ) );

But the root is not shown too.
The proxy is the last option you said, sounds hard to just have a root :/
But the good point is proxy can show multiple tree if I understand what you said.
Is it possible to have more information about this proxy since I never wrote a proxy model ?

wysota
9th June 2014, 14:06
As I said the root is by definition not shown in the view. You need to have a model that has only one element on the top-most level -- your "root" and attach the "real data" to this single element as its children.