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. [SOLVED] Reimplementing sort for a QTreeView
Forum Update on Monday, May 27th 2025

[SOLVED] Reimplementing sort for a QTreeView

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.8k 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.
  • M Offline
    M Offline
    Moschops
    wrote on 14 Nov 2013, 09:15 last edited by
    #1

    I have a standard issue QDockWidget, containing a QWidget, containing a QTreeView.

    Various columns are created, and the QTreeView is sortable by column. However, I don't like the sort. At this stage, I want to make it case insensitive, and later there may well be more.

    When I went looking, I found lots of examples showing people subclassing QTreeWidget and then implementing their own operator < function, which is fine, although when I look in the QTreeWidget documentation http://qt-project.org/doc/qt-4.8/qtreewidget-members.html there is no mention of it having an operator <. Where's the documentation about that?

    Should I do the same thing for a QTreeView to implement my own sorting? Subclass it, use the subclass in place of the QTreeView, and implement my own operator < ?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jeroentjehome
      wrote on 14 Nov 2013, 09:34 last edited by
      #2

      Hi,
      Instead of subclassing, placing a QSortFilterModel between your View and your data model could do the trick just as well.
      "QSortFilterModel":http://qt-project.org/doc/qt-4.8/qsortfilterproxymodel.html

      Greetz, Jeroen

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Moschops
        wrote on 14 Nov 2013, 09:41 last edited by
        #3

        A new class to learn about; thanks for pointing it out to me. Certainly looks like that's what I am meant to use for this, so I will. Many thanks.

        Out of interest, does anyone know if subclassing QTreeView and writing my own operator < would have worked as well? I can't find anything about operator < in the documentation (even for QTreeWidget), which is a little unnerving; I only know it exists from other people's forum posts. The word "operator" doesn't turn up anywhere in the QtreeWidget class reference, so where can I read about it?

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cincirin
          wrote on 14 Nov 2013, 12:09 last edited by
          #4

          I think you saw in other forums is to re-implement "QTreeWidgetItem::operator<":http://qt-project.org/doc/qt-4.8/qtreewidgetitem.html#operator-lt

          1 Reply Last reply
          0
          • J Offline
            J Offline
            Jeroentjehome
            wrote on 14 Nov 2013, 16:42 last edited by
            #5

            If you feel the topic is solved, please place [SOLVED] in front of your first post!

            Greetz, Jeroen

            1 Reply Last reply
            0

            1/5

            14 Nov 2013, 09:15

            • 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