[SOLVED] Reimplementing sort for a QTreeView



  • 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 < ?



  • 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



  • 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?



  • 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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.