from PyQt4.QtGui import *
from PyQt4.QtCore import *

class TableView(QTableView):
    
    def __init__(self, parent=None):
        super(TableView, self).__init__(parent)
        self.resize(400, 400)

    def selectionChanged(self, selected, deselected):
        super(TableView, self).selectionChanged(selected, deselected)
        self._selection1 = self.selectionModel().selection()
        self._selection2 = self.selectionModel().selection()
        self._selectedIndexes1 = self.selectionModel().selectedIndexes()
        self._selectedIndexes2 = self.selectionModel().selectedIndexes()
        print 'cmp selection', self._selection1 == self._selection2
        print 'cmp selection indexes', self._selection1.indexes() == self._selection2.indexes()
        print 'cmp selectedIndexes', self._selectedIndexes1 == self._selectedIndexes2

if __name__ == '__main__':

    import sys
    import random

    app = QApplication(sys.argv)

    model = QStandardItemModel(10, 3)
    tableView = TableView()
    tableView.setModel(model)
    
    for row in range(10):
        for column in range(3):
            index = model.index(row, column, QModelIndex())
            model.setData(index, random.randint(0, 100))

    tableView.setWindowTitle("Tableview")
    tableView.show()
    sys.exit(app.exec_())
