How to show only one root folder in tree view

  • 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.

  • Moderators

    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.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.