[PyQt] QAbstractTableModel.sort() is called when QTableView.setSortingEnabled(True) is set

Bjorn Egil Ludvigsen bludvigsen at gmail.com
Sat May 1 04:00:20 BST 2010


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

Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)]
on BEL, Standard
>>> 2010-04-30 21:33:56,012 DEBUG table sorted!
2010-04-30 21:33:56,022 DEBUG table sorted!

    def sort(self, column, order):
        """
        Sort table by given column number.

        @param column the column clicked in the header (integer)
        @param order the sorting order (Qt.Descendingorder |
Qt.Ascendingorder)
        """
        self.emit(SIGNAL("layoutAboutToBeChanged()"))
        self.uncertainties = sorted(self.uncertainties,
key=itemgetter(column))
        if order == Qt.DescendingOrder:
            self.uncertainties.reverse()
        self.emit(SIGNAL("layoutChanged()"))
        logging.debug("table sorted!")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100430/c16ad45f/attachment.html>


More information about the PyQt mailing list