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 14 Feb 2020, 19:49 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

    J 1 Reply Last reply 14 Feb 2020, 20:09
    0
    • F Folling
      14 Feb 2020, 19:49

      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

      J Offline
      J Offline
      JonB
      wrote on 14 Feb 2020, 20:09 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 14 Feb 2020, 21:22 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!

        J 1 Reply Last reply 15 Feb 2020, 10:58
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 14 Feb 2020, 21:36 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
            14 Feb 2020, 21:22

            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!

            J Offline
            J Offline
            JonB
            wrote on 15 Feb 2020, 10:58 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

            1/5

            14 Feb 2020, 19:49

            • Login

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