def mousePressEvent(self, event):
        """Reimplement Qt method"""
        if event.button() != Qt.LeftButton:
            QTableView.mousePressEvent(self, event)
            return
        index_clicked = self.indexAt(event.pos())
        if index_clicked.isValid():
            if index_clicked == self.currentIndex() \
               and index_clicked in self.selectedIndexes():
                self.clearSelection()
            else:
                QTableView.mousePressEvent(self, event)
        else:
            self.clearSelection()
            event.accept()
def mousePressEvent ( self , event ) : if event . button ( ) != Qt . LeftButton : QTableView . mousePressEvent ( self , event ) return index_clicked = self . indexAt ( event . pos ( ) ) if index_clicked . isValid ( ) : if index_clicked == self . currentIndex ( ) and index_clicked in self . selectedIndexes ( ) : self . clearSelection ( ) else : QTableView . mousePressEvent ( self , event ) else : self . clearSelection ( ) event . accept ( )
Reimplement Qt method