PDA

View Full Version : QTreeView: expand(), expandAll(), setExpanded() not work



jasonhxs
27th July 2014, 06:45
Hi,

When I create a QTreeView with QStandardItemModel, I could see the QStandardItems in the tree view.
I try to expand some of them by expand() or setExpanded(), but it doesn't work.
Then I try to expand all by expandAll(), it doesn't work also.
I can see isExpanded() return TRUE after the calling above.
It should be something wrong with my QTreeView. Any idea? Thanks.

jasonhxs
28th July 2014, 11:27
Complement:
I found when I do some GUI action later, the expansion works.
Now the question is why it couldn't work immediately.

d_stranz
29th July 2014, 04:47
expand() and expandAll() are slots. setExpanded() probably invokes one of these slots. It probably doesn't work because your code doesn't return to the Qt event loop so it can handle the calls to the slots. The fact that it doesn't happen until you "do some GUI action later" is a big clue.

The trick is to change your app so it isn't compute bound - a major cause of GUI unresponsiveness.

wysota
29th July 2014, 17:23
Complement:
I found when I do some GUI action later, the expansion works.
Now the question is why it couldn't work immediately.

Please post a minimal compilable example reproducing the problem.

jasonhxs
31st July 2014, 08:18
It is hard to reproduce it, since my code is a little more.
Any suggestion to make it work immediately, like calling some APIs.

wysota
31st July 2014, 09:48
It is hard to reproduce it, since my code is a little more.
Any suggestion to make it work immediately, like calling some APIs.

If you can't reproduce the problem with a small example then it is likely that the problem originates in your own code and if so, then without knowing where the problem lies it is hardly possible to suggest a solution. I suggest you spend 20 minutes trying to assemble a minimal compilable example reproducing the problem.

jasonhxs
13th August 2014, 15:51
Hi all,

I found the root cause, it is because I called model->clear() in somewhere, it will impact the data that was inserted in model.
After I remove it, the expanison works well. Thanks all~