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. Can i define differnt sort role to each column ?
Qt 6.11 is out! See what's new in the release blog

Can i define differnt sort role to each column ?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 4.2k 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.
  • U Offline
    U Offline
    umen242
    wrote on last edited by
    #1

    Hello
    currently im using SortRule in my QStandardItemModel that is based on Qt::UserRole
    but this definition is globally to all the treeview .
    can i define different sort rule to each set of vertial cell's ?
    so for example if i have:
    @m_model->setHeaderData(0, Qt::Horizontal, QObject::tr("Group"));
    m_model->setHeaderData(2, Qt::Horizontal, QObject::tr("Id"));@

    the first Group cells will be sorted by Qt::UserRole and the second Id will be sorted by Qt::DisplayRole

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      I think you' ll need to subclass QSFPM and reimplement lessThan, after which you can compare on the role that you want for the indicated column.

      1 Reply Last reply
      0
      • U Offline
        U Offline
        umen242
        wrote on last edited by
        #3

        wow where can i find example how to do that ?
        found ..
        "http://www.java2s.com/Code/Cpp/Qt/SubclassQSortFilterProxyModel.htm":http://www.java2s.com/Code/Cpp/Qt/SubclassQSortFilterProxyModel.htm

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dialingo
          wrote on last edited by
          #4

          You can have custom sorting for each column though there is only one sort role for the treeview. You define the sort order by writing values into the custom field that determine the position when sorting. You can even use different types in different columns. Or you can use a specific custom type for every column. Just make sure your custom type is registered with QVariant and defines a comparison operator.

          1 Reply Last reply
          0
          • U Offline
            U Offline
            umen242
            wrote on last edited by
            #5

            Thanks allot for answering

            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