QSortFilterProxyModel sorts when not necessary

JPFrancoia

I use a QSortFilerProxyModel with my QTableView, and I initialize it this way:

self.proxy = QtGui.QSortFilterProxyModel()
self.proxy.setSourceModel(self.model)
self.proxy.setDynamicSortFilter(True)

My QTableView uses a model, with some fields like journal, title, and new. When I click on a row, if "new" is True, I modify the model, and set new to False.

My problem is when I sort my rows with the field "journal". Some rows have the same journal, and if I click on a "new" row (which triggers a model change), the proxy sorts the rows in a different way, while I didn't ask for it.

I get this behavior only if I modify the model. So, I would need a way to avoid the update of the QSortFilterProxyModel after a model update. My model is a QSqlTableModel.

Is it possible ?

EDIT: actually, my proxy sorts after each model update, and each time it compares cells with the same value, it ends up with a different sorting order. It's not the expected behavior.

JPFrancoia

I finally found the answer by myself.

Actually, sorting my rows by clicking on the header destroys the proxy. So I subclassed the proxy:

from PyQt4 import QtGui


class ProxyPerso(QtGui.QSortFilterProxyModel):

    def __init__(self, parent):
        super(ProxyPerso, self).__init__(parent)

        self.parent = parent

    def sort(self, column, order):
        super(ProxyPerso, self).sort(column, order)

        self.parent.proxy.setSourceModel(self.parent.modele)
        self.parent.tableau.setModel(self.parent.proxy)

And now it works perfectly.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related