PDA

View Full Version : Reset QTableWidget sorting order



phil333
28th February 2017, 11:50
I am currently working with QTableWidget and I have enabled the column sorting order for the user. I need to be able to switch this sorting order off again. Most other UI appraches allow you to click cycle trough sorting options, descending/ascending/resetOrder. Is this feature available?

I also tried resetting the order with an additional context menu, but I could only find reset options for qTableView, not qTableWidget:
http://stackoverflow.com/questions/18637727/restore-original-order-in-qtableview-qsortfilterproxy

Is there anything that I am missing here?

Santosh Reddy
1st March 2017, 08:34
There is no direct API or trivial way to restore the original order with QTableWidget as you don't have access to it's model. There is a simple ways for QTableView because you can change the model.

A not so straight forward approach would be to some how record and store the un-sorted order of items, and restore it back manually programming it. It may involve re-creation of QTableWidgetItems, it depends on your data model and items.