QTreeView and QFileSystemModel problem
malch last edited by
I am using QTreeView with QFileSystemModel and have some basic stuff working nicely. On initializing the QTreeView I expand the first node (which is mapped to my file system root) to give me a list of all the top level directories on my system.
However, every item listed is shown as expandable (with children). Even the empty directories.
After expanding items over a period of time, the QTreeView will eventually update and remove the expansion indicators from the empty top level directories (which is what I want). But it can take a while and some clicking.
I understand QFileSystemModel examines the disk in a separate thread and I assume it's building its internal structures which seems reasonable. Seems to me it should use a breadth-first .v. depth-first traversal though.
Anyway, it there some easy method of having it more quickly check only the currently displayed nodes to see if they have at least one child and hiding the expansion indicator if not? No need to recurse through the entire file system -- just one level below the currently display items.
Hi, welcome to devnet.
It definitely does not traverse entire filesystem. That would take forever, eat all your RAM and literally kill hard drives (especially SSDs). The reason you see those branch indicators is precisely because it does not go inside until you actually open the directory. In that case it looks for children and if there are none it removes the indicator.
malch last edited by
Thanks Chris. This is a good thing :-)
But I still find the behavior odd.
- Start with only the file system root expanded.
- Expand an empty directory (/cdrom).
- Expand another empty directory (/lost+found).
- Expand another empty directory (/media).
- Expand another empty directory (/mnt).
At this point all 4 empty directories are shown as expandable.
- Expand a directory with children (/opt).
This last step forces an update and the expansion indicator is finally removed from all 4 empty directories.
That doesn't seem wonderful to me. But if that's how it's going to be, I can have my QTreeView derived class check each of the currently displayed directories to see if they contain any children and update the display accordingly. My question is how to do that? And how to do it in a manner that will play nicely with QFileSystemModel?
I should mention I'm running Qt 5.5 under Linux Mint Xfce 17.3 within a VirtualBox guest on a Win 7 Pro system (just in case this turns out of be a VirtualBox related quirk!)