PDA

View Full Version : QSortFilterProxyModel::insertRows always adds rows to the end



Agnostic Pope
7th May 2012, 18:15
So I've got a QSortFilterProxyModel with a QAbstractTableModel underneath.

Before I sort the table, inserting rows works fine. If I put a row in at 3, for example, 3 moves to 4, etc.

Once I sort the table however, inserting a row always goes at the end of the beginning and this behavior appears random. Is there a good way of doing this? Here's what I've tried:

* Using mapToSource. Unfortunately, since the index doesn't exist yet, this doesn't work.
* The default method, QSortFilterProxyModel::insertRows. This fails as described above.

I've tried looking at Qt's source code as well and it appears that I'd need to basically create a mapping inside the proxy model for the correct index before creation, but I'm not quite sure how to do that using the public API. I'll keep looking, but if anyone can help me out here, I'd appreciate it;)

ChrisW67
7th May 2012, 23:23
Are you falling foul of this? From the docs:

Note: By default, the model does not dynamically re-sort and re-filter data whenever the original model changes. This behavior can be changed by setting the dynamicSortFilter property.

Perhaps you could post a small, self-contained program that demonstrates the problem.