“expandBelow” in TreeView: Shortcut vs. method
using PyQt I’ve got a major performance issue with my hand-coded “expandBelow” method of a QTreeView, which is supposed to expand the tree recursively below a selected row. However, there’s a key shortcut for this action (at least on Windows): the “*” key. Despite not being as fast as the expandAll method (which is incredibly fast) it’s considerably faster then my Python method.
Any ideas, how the behaviour of the “*” key is implemented and how I could access it from PyQt?
In general, a treeview has a method for that:
You could try it.
But it expands only one level. In my code I call this method for all children recursively. And that takes quite a long time. Here’s the Python code I’m using:
- def expand_below_recursive(self):
- index = self.selectedIndexes()
- q = deque([index])
- while q:
- idx = q.popleft()
- for i in range(self.model.rowCount(idx)):
- q.append(self.model.index(i,0, idx))
By the way, browsing the source I’ve found a merge request for methods “expandBranch” and “collapsBranch”. They don’t seem to have made it to Qt 4.8, do they?
As I’m not used to git I’m not sure what it all means. Status is “update”, but the last reply in the thread is over a year old. Looks like it hasn’t been pursued.
Ok, “Lab Rat” mistake:
I had the expanded-signal connected to the resizeColumn-slot. The resizeColumn method is called on every expansion which is the culprit for the bad performance. As the expandAll method and probably the “*”-triggered expansion don’t trigger the expanded-signal, the resizeColumn-method is not called in these cases.
Now the Python method listed above is lightening fast. Hurray for Python … and Qt, of course. ;-)
Yes, but that site has been open now for just over week, while the MR was in gitorious for well over a year now. I certainly hope the MR will be pushed to the new system, but I fear that not seeing your MR being taken up for more than a year can be such a demotivating experience that contributers won’t bother anymore.