Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved Notifying model QSortFilterProxyModel / QIdentityProxyModel of model data change?

    General and Desktop
    qabstractitemmo qsortfilterprox qidentityproxym qdrag drag drop
    3
    3
    1038
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      Dariusz last edited by Dariusz

      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.

      1 Reply Last reply Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

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

        (Z(:^

        innermous 1 Reply Last reply Reply Quote 2
        • innermous
          innermous @sierdzio last edited by

          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.

          1 Reply Last reply Reply Quote 3
          • First post
            Last post