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. Tablesort
Qt 6.11 is out! See what's new in the release blog

Tablesort

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 1.4k Views 1 Watching
  • 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.
  • MegamouseM Offline
    MegamouseM Offline
    Megamouse
    wrote on last edited by
    #1

    I want my table to be always sorted alphabetically by its second column after it was sorted by another.

    Like if i have 3 cells in column 2 that all have the same value I want those three rows to be sorted by its first column

    not sorted:

    hello   | 1
    my      | 5
    friends | 1
    

    sorted by second column ('hello' and 'friends' are wrong):

    hello   | 1
    friends | 1
    my      | 5
    

    sorted by second column (preferred):

    friends | 1
    hello   | 1
    my      | 5
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You might be interested by the QxtSortFilterProxyModel class.

      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
      1
      • MegamouseM Offline
        MegamouseM Offline
        Megamouse
        wrote on last edited by
        #3

        I don't want to use Qxt, I don't even know what that is

        SGaistS 1 Reply Last reply
        0
        • MegamouseM Offline
          MegamouseM Offline
          Megamouse
          wrote on last edited by Megamouse
          #4

          why isn't there a setter for "defaultSortColumn" or something like that....
          And why can't I override QTableWidget::sortItems to do that myself....

          1 Reply Last reply
          0
          • MegamouseM Megamouse

            I don't want to use Qxt, I don't even know what that is

            SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Megamouse said in Tablesort:

            I don't want to use Qxt, I don't even know what that is

            Then before saying no, you could take the time to check. Note, that in this case, it won't help you, I mixed filtering and sorting so whatever...

            @Megamouse said in Tablesort:

            why isn't there a setter for "defaultSortColumn" or something like that....
            And why can't I override QTableWidget::sortItems to do that myself....

            Because for more advanced sorting and filtering there's QSortFilterProxyModel.

            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
            1
            • MegamouseM Offline
              MegamouseM Offline
              Megamouse
              wrote on last edited by
              #6

              wow that's awfully complicated for a common feature like that

              1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                QTableWidget is a convenience class - if you need more control over the data you have to use QTableView and a custom model.
                For you problem it should be enough to derive from QTableWidgetItem and override
                operator <(const QTableWidgetItem &o) const

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                2
                • MegamouseM Offline
                  MegamouseM Offline
                  Megamouse
                  wrote on last edited by
                  #8

                  thx. I forgot I already have that operator override, I'll adjust it accordingly.

                  1 Reply Last reply
                  0

                  • Login

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