[Interest] Question about advice regarding dynamicSortFilter of QSFPM in the docs
Elvis Stansvik
elvstone at gmail.com
Wed Jun 1 09:02:16 CEST 2016
2016-06-01 8:54 GMT+02:00 Elvis Stansvik <elvstone at gmail.com>:
> Hi all,
>
> I've used QSortFilterProxyModel in the past, but it was quite a while
> ago and now I'm a little confused by the advice given in the docs.
>
> The description of the dynamicSortFilter property [1] reads:
>
> "Note that you should not update the source model through the proxy
> model when dynamicSortFilter is true. For instance, if you set the
> proxy model on a QComboBox, then using functions that update the
> model, e.g., addItem(), will not work as expected. An alternative is
> to set dynamicSortFilter to false and call sort() after adding items
> to the QComboBox.
>
> The default value is true."
>
> I can't remember this restriction from when I've worked with it
> before, and in the class description, underneath the second code
> snippet, it says:
>
> "Any changes made through the QSortFilterProxyModel are applied to the
> original model."
>
> As if it is safe to update the model through the QSFPM at this point,
> even if it is speaking of one where dynamicSortFilter is true (the
> default).
>
> Surely it must be possible to use a QSFPM with dynamicSortFilter set
> to true as the model of some view which also provides editing (and
> consequently will make its changes through the QSFPM)? Or is that
> simply not a supported use case? If I use dynamicSortFilter, must I
> always make my changes to the source model?
As a simple concrete example, say I create a QStringListModel, wrap it
in a QSFPM (leaving dynamicSortFilter enabled) and set that QSFPM as
the model of a QListView with editing enabled.
The docs make it sound like that's inadvisable (since the QListView
will perform its editing through the dynamically sorted QSFPM). Is
that right?
Elvis
>
> Grateful for any advice,
> Elvis
>
> [1] http://doc.qt.io/qt-5/qsortfilterproxymodel.html#dynamicSortFilter-prop
> [2] http://doc.qt.io/qt-5/qsortfilterproxymodel.html#details
More information about the Interest
mailing list