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. How to setSortRole for QTreeWidget ?

How to setSortRole for QTreeWidget ?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.0k 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.
  • A Offline
    A Offline
    Anticross
    wrote on last edited by
    #1

    I have QTreeWidget based class and need to do sorting by Qt::UserRole. How can I do this ? I know that QStandartItemModel has such method and treeWidget has model() method which return model, but it's QAbstractItemModel type which has no setSortRole method.

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

      QSortFilterProxyModel seems the obvious choice. It supports a sortRole property you can use to set the role you want to sort on.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Anticross
        wrote on last edited by
        #3

        Yes, but I use QTreeWidget, non view and setModel is private method in QTreeWidget. So I can't do this: @QSortFilterProxyModel sortModel;
        sortModel.setSourceModel(model());
        setModel(&sortModel);@

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

          Ah, yes, right.
          I'd suggest to move away from QTreeWidget towards using QTreeView then :-) The API for QStandardItemModel is quite similar to the API of QTreeWidget for items, so the changes to your code should be minimal.

          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