FileTreeComponent doesn't restore openness after refresh

gui

#1

I have a FileTreeComponent showing a nested folder structure. When I expand some of them and then call refresh(), they collapse. So I create an OpennessRestorer before calling refresh(), but that doesn’t work. The reason seems to be that refresh() clears the list of children, so then we would have to wait for it to be filled asynchronously again. restoreOpennessState() doesn’t seem to do that.

A small example that shows this: FileTreeTest.zip. In the example, I noticed that the initial expanding works if I uncomment line 47, to wait for the async/background update. I would like to avoid that line, if possible.

How can I fix this, or work around it? :slight_smile:

There are some old topics on this, e.g. this one. You can find them by searching for “FileTreeComponent openness”.


#2

Because a FileTree loads child-trees dynamically in background thread you have to give it some time and reapply the opennessState a few times, so that the restoring can be applied to child-trees.

Here is one solution, maybe there are some more elegant solutions at this forum


#3

Thanks for the reply. But that doesn’t seem to solve it: It only works when you have just one nesting level.

In my example, I have a nested folder hierarchy. I think the problem is that TreeViewItem::restoreOpennessState calls itself recursively, without waiting. So even if we wait on the outside (your code with the timer), the TreeViewItem won’t wait before recursing into its children.