Results 1 to 8 of 8

Thread: QFileSysremModel + QTreeView : root with a custom name ?

  1. #1
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Exclamation QFileSysremModel + QTreeView : root with a custom name ?

    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

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QFileSysremModel + QTreeView : root with a custom name ?

    Show some code and a screen shot please. Can I assume you have set the root to what you want using QFileSystemModel::setRootPath?
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  3. #3
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFileSysremModel + QTreeView : root with a custom name ?

    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.
    Last edited by Alundra; 4th July 2015 at 00:37.

  4. #4
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QFileSysremModel + QTreeView : root with a custom name ?

    Have you tried using QTreeView::setRootIndex?
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  5. #5
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFileSysremModel + QTreeView : root with a custom name ?

    This is what I do to set the good root :
    Qt Code:
    1. m_ListTree->setRootIndex( ListTreeModel->index( ListTreeModel->rootPath() ) );
    2. m_ListTree->setCurrentIndex( m_ListTree->rootIndex() );
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QFileSysremModel + QTreeView : root with a custom name ?

    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.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  7. #7
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFileSysremModel + QTreeView : root with a custom name ?

    Here the list + model code :
    Qt Code:
    1. // List tree model.
    2. CFileSystemModel* ListTreeModel = new CFileSystemModel( this );
    3. ListTreeModel->setFilter( QDir::NoDotAndDotDot | QDir::AllDirs );
    4. ListTreeModel->setIconProvider( new CFileIconProvider );
    5. ListTreeModel->setRootPath( "Content/" );
    6. ListTreeModel->setReadOnly( false );
    7.  
    8. // List tree.
    9. m_ListTree = new CContentBrowserListTreeView( this );
    10. m_ListTree->setModel( ListTreeModel );
    11. m_ListTree->setItemDelegate( new CFileSystemListDelegate( m_ListTree, this ) );
    12. m_ListTree->setRootIndex( ListTreeModel->index( ListTreeModel->rootPath() ) );
    13. m_ListTree->setDragDropMode( QAbstractItemView::DragDrop );
    14. m_ListTree->setCurrentIndex( m_ListTree->rootIndex() );
    15. m_ListTree->setDefaultDropAction( Qt::MoveAction );
    16. m_ListTree->setDropIndicatorShown( true );
    17. m_ListTree->setHeaderHidden( true );
    18. m_ListTree->setDragEnabled( true );
    19. m_ListTree->hideColumn( 1 );
    20. m_ListTree->hideColumn( 2 );
    21. m_ListTree->hideColumn( 3 );
    22. m_ListTree->setMinimumWidth( 150 );
    23. m_ListTree->setContextMenuPolicy( Qt::CustomContextMenu );
    To copy to clipboard, switch view to plain text mode 
    The goal is to have a root for each folder and have a custom name for each root like that :
    https://answers.unrealengine.com/sto...p/3696-ddd.png
    Last edited by Alundra; 4th July 2015 at 11:58.

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QFileSysremModel + QTreeView : root with a custom name ?

    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,
    _

Similar Threads

  1. Need to remove root node from QTreeView
    By tescik in forum Qt Programming
    Replies: 4
    Last Post: 24th April 2014, 10:54
  2. Replies: 7
    Last Post: 7th December 2010, 05:36
  3. QTreeView: include root in tree?
    By meter in forum Newbie
    Replies: 2
    Last Post: 14th June 2010, 13:59
  4. Replies: 1
    Last Post: 10th June 2010, 06:35
  5. Direct root childs inline QTreeView
    By faraslacks in forum Qt Programming
    Replies: 2
    Last Post: 15th January 2009, 08:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.