[PyQt] Performance problems with QSortFilterProxyModel

Bjorn Egil Ludvigsen bludvigsen at gmail.com
Wed May 12 13:50:56 BST 2010


I sent and email with maybe a related issue a few weeks back. This email
does not seem to have reached the mailing list, so here it is again. I have
an issue with the sort() method that seems to be called too often. I know
there have been some issues previously, and that Mark recommended in his
book to turn off the setSortingEnabled() before populating a QTableWidget().
This issue is supposed to have been solved, but maybe not?

I am looking at a model with up to 1 million rows (as a benchmark and future
reference) so I would really like to know about potential problems.

Regards,
Bjorn

Hi,

I have a QAbstractTableModel with a reimplemented sort() method. The model
is set with a QTableView with horizontal headers. The sort() method is
supposed to be called only when I click on a header section, which it
successfully does, and everything is working fine in that sense. However,
the sort() method is called 2 times when the application starts up when the
setSortingEnabled(True) is set (if setSortingEnabled(False), then sort is
not called).

Why is the sort method called 2 times without me clicking anywhere nor
calling the method explicitly? I have been looking into the order of things
when starting up the application, but cannot see any difference in whatever
I try. This is a problem for large data sets. The model.sort() method is
given below with the output.

Regards,
Bjorn

On Wed, May 12, 2010 at 1:04 AM, Mark Summerfield <list at qtrac.plus.com>wrote:

> On 2010-05-12, Steve Borho wrote:
> > Hello,
> >
> > The TortoiseHg project is currently porting all of our PyGTK apps to
> > PyQt, This has been going pretty well so far, but I've hit a snag with
> > our file status browser.
> >
> > I have a simple QAbstractTableModel (4 columns) being displayed in a
> > QTreeView.  After connecting a QSortFilterProxyModel between the tree
> > view and the data model, reloading the model became very expensive for
> > moderately sized data sets.  After calling setSourceModel() with a
> > model of 555 rows, I counted over 3 million calls to the model data()
> > method, which takes about 15 seconds.
>
> Have you tried switching off sorting just before resetting the model and
> then switching it back on afterwards?
>
> [snip]
>
>
> --
> Mark Summerfield, Qtrac Ltd, www.qtrac.eu
>    C++, Python, Qt, PyQt - training and consultancy
>        "Programming in Python 3 (Second Edition)" - ISBN 0321680561
>  _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100512/e85f61e2/attachment.html>


More information about the PyQt mailing list