Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to show only one root folder in tree view

How to show only one root folder in tree view

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 724 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xalam
    wrote on last edited by
    #1

    I am using QFileSystemModel in a tree view but I want to show only one folder view. I also want that folder to appear as the root folder (and no other sibling folders). I am doing something like this:

    @ QModelIndex rootIndex = dirModel->index( sourcePath );

    ui->treeViewFileSystem->setModel( dirModel );
    ui->treeViewFileSystem->setRootIndex( rootIndex );@
    

    With this I get the right view of folder that I want but that folder itself is not displayed as the root folder. How can have it displayed?

    I also tried rootIndex.parent() but than it shows all sibling folders of the parent. Also I am trying to show dotted lines in the tree view that emanates from root folder, will be nice.

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      the only way i can think of is that you use a QSortFilterProxyModel und filter out all siblings so that it is the only root node left.
      This should be just few lines of code.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved