Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Custon sorting behaviour when clicking on a Qtableview header
hachbani last edited by
I want to implement the following behaviour:
- the first click on a header sort the table in ascending order
- a second click sort on same header sort it in descending order
- a third click goes back to my default sorting (which I already implemented in lessThan() method in my Proxy method)
I have a Qtableview, set to a QSortFilterProxyModel (subclassed) and a QAbstractTableModel (subclassed). Working on Pyside2
I would like to implement this in my ProxyModel
any hints on how to do that, I don't know how to get started in this.
JonB last edited by JonB
Well you sound like you are almost there already! You have picked the right hierarchy.
Since you have three states, at some level you need to note that so you know where you are, and move through them as desired from clicking. You probably want this "state flag" stored in the sub-classed
QSortFilterProxyModel, so that knows what it should do about which sorting to apply. Then the UI deals with the clicks and tells the proxy model to move through the 3 states.