Sorting TreeView skip certain rows
Hi,
I have a treeView using a custom model. I want to sort on certain levels of the tree. For example, lets say level 1 is fruits, level 2 is apples, and level 3 is types of apples. I want to skip sorting on level 3 (types of apples). My level 3 has a lot of items and it causes a decent pause when Qt tries to sort them. Is this possible? How would you do it? I'm using QSortFilterProxyModel, but re-implementing lessThan doesn't help because the sort still goes through all the items. Using QT4.4. Thanks.
Re: Sorting TreeView skip certain rows
reimplement lessThan to return
Code:
{
// assuing apples (and only apples) are on the 3rd level
return idx.parent().parent().isValid();
}
{
if (on_apple_level(left))
return left.row() < right.row();
// other comparisons
}
HTH
Re: Sorting TreeView skip certain rows
if you are using your custom model you can reimplement it's QAbstractItemModel::sort() method, which can sort your data structure, which you use inside the custom model to store data. So in that method you can implement sorting in your own way, for example to skip sorting the 3. level. But this is sorting internal source model data structure, which is very different from proxy model approach , where the source model stays unchanged.
Re: Sorting TreeView skip certain rows
Thanks! I went ahead and tried the less than implementation and by doing what you suggested it works farely well. There is a slight pause, but much better than before.