How to sort TreeView Items using QSortFilterProxyModel based on a Combobox selection

  • I have a TreeView in my app. I limit the displayed rows using a class which is inherited from QSortFilterProxyModel. I also need to sort the items in the TreeView based on selectedIndex of a combobox.
    What I did so far is:

    • When the selected Index of the combo box changes, I will call a function in the class inherited from QSortFilterProxyModel which calls sort(0) function.

    • In the class inherited from QSortFilterProxyModel, I have overridden the lessThan function and implemented my logic based on the current selection in the ComboBox

    The problem is, the sorting does not always happen. When I run the app, and I choose an item in the combobox, the tree items get sorted correctly. But if I select another item in the combobox, the Tree will not get updated. The lessThan function will get called, though!

Log in to reply

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