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

Notifying model QSortFilterProxyModel / QIdentityProxyModel of model data change?



  • Hey

    I have

    MyModek(QAbstractItemModel)>myProxyModel(QIdentityProxyModel)>myFilterProxy(QSortFilterProxyModel) model system.

    When I perform dropMimeData on my Model I run these 2 commands :

        Q_EMIT dataChanged(newData.first()->index(), newData.last()->index()); /// data is sorted by index top to bottom
        Q_EMIT layoutChanged({p}); /// p is parentIndex node
    

    I've noticed that when I drop items that has a myFilterProxy then the new items don't show up unless I clear up the filter string and retype it in/out to have it re-read full data list from my base model. Even if the string is empty, they do not show up.

    What signal should I emit from my Model to notify the identity and filter models properly?

    TIA


    Sorted, I had to forward signals from my model to proxy then to filter with dataChanged/etc and link it to invalidate on proxy filter.


  • Moderators

    You can call invalidate() or invalidateFilter() to tell your proxy that it needs to redo the filtering or sorting.



  • You may also try to set dynamicSortFilter: true, but only if you do not modify contents of model through proxy model.
    invalidate() calls are expensive and you should only do it when you know what you are doing.
    If you modify contents of your model through proxy model and/or you need to filter and sort on demand, invalidateFilter() and sort() is what you are looking for.