PDA

View Full Version : QFileSysremModel + QTreeView : root with a custom name ?



Alundra
3rd July 2015, 13:20
Hi,
I gave a try long time ago without any success so I'm back for a new try :
Is it possible to have the root of a QTreeView visible using a QFileSystemModel ?
I've made a file browser but since the root is not visible, I can't go back on the root from the TreeView.
If it's possible, is it possible to change the root name to a custom name ?
How solve these issues ?
Thanks for the help

jefftee
3rd July 2015, 20:27
Show some code and a screen shot please. Can I assume you have set the root to what you want using QFileSystemModel::setRootPath?

Alundra
3rd July 2015, 22:10
http://zupimages.net/up/15/27/43on.png
On the left, you can see no root is visible, the only way to go to the root is to click on the root button of my path widget on the top.
EDIT :
Maybe one way is to set the root on the parent and only accept the good row using QSortFilterProxyModel, But if a better way exist it could be nice.
Maybe it's better to make a custom tree view to have full control and show one root item, and have multiple path possible.

jefftee
4th July 2015, 00:50
Have you tried using QTreeView::setRootIndex?

Alundra
4th July 2015, 02:32
This is what I do to set the good root :


m_ListTree->setRootIndex( ListTreeModel->index( ListTreeModel->rootPath() ) );
m_ListTree->setCurrentIndex( m_ListTree->rootIndex() );

jefftee
4th July 2015, 03:21
I am not able to guess what the problem may be and you've posted a whopping 2 lines of code for inspection and no information regarding the value of ListTreeModel->rootPath().

My two cents worth is that if QFileSystemModel doesn't do what you want, then don't use it. You can subclass your own QAbstractItemModel or use QStandardItemModel.

Good luck, perhaps someone else can help you, but in general people will be more likely to help you if you post more of your relevant code.

Alundra
4th July 2015, 10:52
Here the list + model code :


// List tree model.
CFileSystemModel* ListTreeModel = new CFileSystemModel( this );
ListTreeModel->setFilter( QDir::NoDotAndDotDot | QDir::AllDirs );
ListTreeModel->setIconProvider( new CFileIconProvider );
ListTreeModel->setRootPath( "Content/" );
ListTreeModel->setReadOnly( false );

// List tree.
m_ListTree = new CContentBrowserListTreeView( this );
m_ListTree->setModel( ListTreeModel );
m_ListTree->setItemDelegate( new CFileSystemListDelegate( m_ListTree, this ) );
m_ListTree->setRootIndex( ListTreeModel->index( ListTreeModel->rootPath() ) );
m_ListTree->setDragDropMode( QAbstractItemView::DragDrop );
m_ListTree->setCurrentIndex( m_ListTree->rootIndex() );
m_ListTree->setDefaultDropAction( Qt::MoveAction );
m_ListTree->setDropIndicatorShown( true );
m_ListTree->setHeaderHidden( true );
m_ListTree->setDragEnabled( true );
m_ListTree->hideColumn( 1 );
m_ListTree->hideColumn( 2 );
m_ListTree->hideColumn( 3 );
m_ListTree->setMinimumWidth( 150 );
m_ListTree->setContextMenuPolicy( Qt::CustomContextMenu );

The goal is to have a root for each folder and have a custom name for each root like that :
https://answers.unrealengine.com/storage/temp/3696-ddd.png

anda_skoa
4th July 2015, 11:41
That looks like you want an aggregate model that provides the top level elements itself and then delegates every further level to an instance of file system model.

Cheers,
_