And since you are selecting on multiple levels of the tree hierarchy, your sort condition needs to not only take into account the row, but also the parent-child relationship of those rows. (E.g. both "Path 1902" and "path_group" could have a row index of zero).
This would be especially important if you selected two top-level groups - then you would have duplicate row indexes for each of the two "Path" parents.
If what you want to do is to allow extended selection, but in effect select all children of the selected "Path" nodes, then I would iterate over the returned list of QModelIndex entries, pull out only the Path nodes into another list and sort that new list by row number. Then I would go over that sorted list and pull all of the child nodes of each Path node out of the model and insert those into the sorted list following their parent Path node. Everything will then be in the same order as it appears in the tree.
In effect, you ignore the child nodes returned by the initial selection, but then go back into the model and pull out the complete list of them based on the Path nodes that were selected.
Bookmarks