Qt QFileSystemModel - Multiple directory trees under the root index

c++, qt, treeview

Solution

I would suggest creating a custom model, perhaps derived from `QAbstractItemModel`, that had some top level entity (off screen) to which you could parent multiple `QFileSystemModels`, one for each top level directory you wanted to display. This would allow you to manipulate each tree in a different way, depending on what type of directory it was displaying.

Problem

I'm trying to create a `QTreeView` using `QFileSystemModel` that will display multiple directory trees under the root index of the tree. I'm currnetly using the following code: ``` QFileSystemModel *model = new QFileSystemModel(); QTreeView *tree = new QTreeView(); model->setRootPath(QDir::rootPath()); tree->setModel(model); ``` Using this, the file tree will display a single item (the root of the file system). What I'd like to do, though, is be able to display the root of the file system and have several specific directories and unrelated subtrees as siblings. Below is an image of the desired behaviour from a different application. The first two items are specific folders within the file system, acting like shortcuts. The last item is unrelated to the file system.

Original source