Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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



  • @Folling
    So can't you handle the clicks and set sorting off/on-up/on-down there?



  • I suspect I can, though that would require subclassing of both the proxy model as well as the tree/table-views. I just wanted to make sure I'm not overlooking some trivial solution to this problem!


  • Lifetime Qt Champion

    Hi,

    You might want to check QHeaderView::sectionClicked.

    With that you can have the control you want without necessarily doing that much subclassing.



  • @Folling

    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.


Log in to reply