QTableview, allow third click to disable sorting
-
With a QTableView and a QSortFilterProxyModel you can allow sorting.
So far so good. It starts in ascending order, one click toggles it to descending, and vice-versa.However I would like something similar to how spotify does it.
It starts in the order of insertion, i.e. an order which corresponds directly to the indices of the model. One click switches to sorting in ascending order, another to sort descendingly, and a third one toggles it off again.Here's a video as demonstration: https://cdn.discordapp.com/attachments/677605877141864497/677963932010283008/2020-02-14_20-46-10.mp4
In addition I would like to disable reordering when the view is sorted.
I haven't found a way to provide this functionality, yet it seems so trivial. Any help is appreciated
-
Hi,
You might want to check QHeaderView::sectionClicked.
With that you can have the control you want without necessarily doing that much subclassing.
-
I suspect I can, though that would require subclassing of both the proxy model as well as the tree/table-views
I'll just say: unless I get shot down by the Qt experts, I tend (left to my own devices) to subclass most of these types of Qt classes right from the start, even when I don't necessarily have anything I want to do yet. Many years of experience have taught me that this makes it easiest to introduce new functionality when it gets required without much rewrite, easier to debug & maintain, etc.