Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Indexes problem with QSortFIlterProxyModel and QStringListModel



  • Hello ,
    I have 4 objects :

    • QStringListModel
    • QSortFilterProxyModel
    • QListView
    • QStackedWidget

    So, QStackedWidget's current widget is changing with the current selection index in QListView. (So if i selected first element -> QStacketWidget will show first element).

    After, i need to add some filter features to QListView -> then i applied some RegExp with QSortFilterProxy, and set QListView's models - QSortFilterProxyModel. So it works fine, but the one moment that, after filtring, all accordings, like Index selection of QListView to QStackedWidget became wrong. :

    example :

    "ITEM 1" - 0
    "ITEM 2" - 1
    "ITEM 3" - 2

    assume like i find "ITEM 3" , after apply regexp, "ITEM 3" will become index 0(cause it's only one and first) in model , so the widget that would be shown is widget with index 0. and must be 3.

    "ITEM 3" - 0

    Can you give me an idea?

    So i have some thoughts about to make an one more column to QStringListModel that will be containing an original idx. is it good, or is there some better sollution ?



  • just call QSortFilterProxyModel::mapToSource to convert a fitered index to the original one


Log in to reply