The code creates a QTableView
and QPushButton
. Pressing the button selects the indexes in continuous order (from index1
to index2
. It is still an unswered question if it would be possible to select the indexes in any order.

def clicked():
tableView.setFocus()
selectionModel = tableView.selectionModel()
index1 = tableView.model().index(0, 0)
index2 = tableView.model().index(1, 2)
itemSelection = QtGui.QItemSelection(index1, index2)
selectionModel.select(itemSelection, QtGui.QItemSelectionModel.Rows | QtGui.QItemSelectionModel.Select)
app = QtGui.QApplication([])
window = QtGui.QWidget()
window.resize(400, 300)
tableView = QtGui.QTableView()
model = QtGui.QStandardItemModel(4, 2)
for row in range(0, 4):
for column in range(0, 3):
item = QtGui.QStandardItem("%s , %s"%(row, column))
model.setItem(row, column, item)
tableView.setModel(model)
selectionModel = QtGui.QItemSelectionModel(model)
tableView.setSelectionModel(selectionModel)
button = QtGui.QPushButton('Select from 0,0 to 1,2')
button.clicked.connect(clicked)
layout = QtGui.QVBoxLayout()
layout.addWidget(tableView)
layout.addWidget(button)
window.setLayout(layout)
window.show()
app.exec_()