Sorting files by name: QFileSystemModel vs QSortFilterProxyModel
-
wrote on 31 Dec 2019, 15:12 last edited by
Hello everybody!
I'm pretty new to Qt and I'm facing this strange problem: as you see in the image below, I'm working on 2 tree views, the one on the left contains the local files and it's based on QFileSystemModel, while the one on the right contains remote files and it's based on QSortFilterProxyModel.
As you can see, the have the same files, both sorted by name, but they have a different order.
Seems like the QFileSystemModel isn't sorting well, what could be the reason?
Have you ever noticed that? Is it a "feature" of Qt or a bug in my code?If it's something of Qt, what would be the best workaround to fix that?
Thanks in advance for your help!
[and happy new year!] -
QFileSystemModel is using QCollator with numericMode on, QSortFilterProxyModel simply sorts the strings without any special stuff
-
QFileSystemModel is using QCollator with numericMode on, QSortFilterProxyModel simply sorts the strings without any special stuff
wrote on 31 Dec 2019, 16:17 last edited by@Christian-Ehrlicher thanks a lot for the quick feedback!
Is it possible to easily "disable" that? Actually I prefer the other way of sorting. -
@myUsername said in Sorting files by name: QFileSystemModel vs QSortFilterProxyModel:
Is it possible to easily "disable" that? Actually I prefer the other way of sorting.
No, but why can't you simply use a QSortFilterProxyModel?
-
@myUsername said in Sorting files by name: QFileSystemModel vs QSortFilterProxyModel:
Is it possible to easily "disable" that? Actually I prefer the other way of sorting.
No, but why can't you simply use a QSortFilterProxyModel?
wrote on 31 Dec 2019, 16:47 last edited by@Christian-Ehrlicher thanks for the clear answer.
I'm going to try to re-implement that using QSortFilterProxyModel.
I was just hoping for an easier solution😅 -
@myUsername said in Sorting files by name: QFileSystemModel vs QSortFilterProxyModel:
I'm going to try to re-implement that using QSortFilterProxyModel.
What do you need to reimplement here? Simply set it as proxy model and you're fine.
-
wrote on 31 Dec 2019, 17:10 last edited by
In order to use QFileSystemModel, you can as well re-implement the "sort" function since the base implementation does nothing:
https://doc.qt.io/qt-5/qfilesystemmodel.html#sortIf you want to sort like the one in the right, I would recommend using the QSortFilterProxyModel as is. If you want something more customizable then re-implementing the QFileSystemModel would be a better option.
-
@myUsername said in Sorting files by name: QFileSystemModel vs QSortFilterProxyModel:
I'm going to try to re-implement that using QSortFilterProxyModel.
What do you need to reimplement here? Simply set it as proxy model and you're fine.
wrote on 31 Dec 2019, 17:33 last edited by@Christian-Ehrlicher Do you mean to use QFileSystemModel as source model for QSortFilterProxyModel?
I would like to be able to use methods, like setRootPath, setFilter, setNameFilters... -
Lifetime Qt Championwrote on 31 Dec 2019, 20:40 last edited by SGaist 1 Jan 2020, 12:27
Hi,
You still can.
It just sits between the view and the other model.
-
wrote on 1 Jan 2020, 09:37 last edited by
Thanks to everybody for the help!
I think I understood what to do.
I just found out the methods mapFromSource and mapToSource, which should allow me to easily switch between the 2 models.
1/10