Sorting QTreeWidget after adding a row
Hello,
I’m programmatically sorting a QTreeWidget using sortItems(int column, Qt::SortOrder order). It works, of course. However, if I do it right after adding some items to the tree, the sort won’t take effect.
I’ve even tried calling sortItems from a one-shot QTimer. This works a little bit better, but still fails 50% of the time. Clearly something needs to be “updated†or validated in the QTreeWidget before the sort will work.
Is there a way to force the QTreeWidget to update so I can call sortItems immediately?
Many thanks.
Re: Sorting QTreeWidget after adding a row
how and where do you call the sort function and how for example do you add a new widget? The error is most probably in the order of calling these functions.
Re: Sorting QTreeWidget after adding a row
Hi there, I'm doing things like this:
Code:
theTree->addTopLevelItem(newItem);
theTree->addTopLevelItem(newItem);
// etc. etc....
// after all items have been added, we then call the following within the same function:
theTree->sortItems(0, Qt::AscendingOrder);
Of course things are a little more complicated than that, with multiple columns etc. But this is how things are added, sorted, and in the order that it happens. I wouldn't think it could be any simpler than this!
Running Qt 4.6.2 if that makes any difference.