Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTableview, allow third click to disable sorting

QTableview, allow third click to disable sorting

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Folling
    wrote on last edited by
    #1

    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

    JonBJ 1 Reply Last reply
    0
    • F Folling

      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

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

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

      1 Reply Last reply
      2
      • F Offline
        F Offline
        Folling
        wrote on last edited by
        #3

        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!

        JonBJ 1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by aha_1980
          #4

          Hi,

          You might want to check QHeaderView::sectionClicked.

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          4
          • F Folling

            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!

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @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.

            1 Reply Last reply
            2

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved