You are using a basic implementation of a tree model. You will notice that it derives from QAbstractItemModel and that it does not override the QAbstractItemModel::sort() method. From the docs you will see:
No sorting ability is what you should expect from this model.void QAbstractItemModel::sort(int column, Qt::SortOrder order = Qt::AscendingOrder)
Sorts the model by column in the given order.
The base class implementation does nothing.
You could extend the custom tree model to provide sorting ability that the view can use directly (harder to get right), or you can insert a QSortFilterProxyModel between your model and the view. There are good examples in the class documentation for the proxy model approach.
Bookmarks