Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QSortFilterProxyModel and dynamic sort

I'm using a class that inherit QSortFilterProxyModel to only do sorting of rows in a table view.

I've enabled dynamicSort to make sure that my view stays sorted even when I load the model or add rows (I've checked that either modelReset() or rowsInserted() are emitted properly by my model).

But for some reason, my rows are not kept sorted.

Is there something specific to do to enable dynamic sorting?

Is just not what setDynamicSortFilter does at all?

Is there a way to manually call sort upon emission of these signals? (every time I try to do it, I get only invalid variants from the model's data(), judging by the source, the signal is emitted before the QSortFilterProxyModel has finished setting things up again)

Anyway, any help is welcomed to try figuring out how this is supposed to work, thank you.

like image 303
Julien Lopez Avatar asked Dec 11 '25 06:12

Julien Lopez


1 Answers

From dynamicSortFilter documentation:

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.

Is there a way to manually call sort upon emission of these signals? (every time I try to do it, I get only invalid variants from the model's data(), judging by the source, the signal is emitted before the QSortFilterProxyModel has finished setting things up again)

I think if you will set dynamicSortFilter to false then your manual calls to sort will not (badly) intercept with QSortFilterProxyModel's internal updates. At least I can tell you that this is what I am doing in a similar scenario and it works for me fine.

like image 191
mvidelgauz Avatar answered Dec 14 '25 01:12

mvidelgauz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!