Skip to content Skip to sidebar Skip to footer

Qtableview: Sort By Header Index -1

I am using PyQt4 and have a QTableView with a 2 columns data. There is an extra column for an index (it comes from the headerData function of the source model). For sorting when cl

Solution 1:

First you must be able to get the cornerWidget which is a QAbstractButton, for that we use findChild. Then we use sort(-1) that invalidates the ordering and places it in the initial state.

class MainWindow(QtGui.QMainWindow):
    def __init__(self):
        ...    
        self.setCentralWidget(self.tableView) 
        cornerButton = self.tableView.findChild(QtGui.QAbstractButton)
        cornerButton.clicked.connect(lambda: self.proxy.sort(-1))

Post a Comment for "Qtableview: Sort By Header Index -1"