pythonqtpyqtqtableviewselectionmodel

How to select multiple rows in QTableView using selectionModel


With:

tableView = QTableView()
rows = [0, 1, 2]

tableView.selectRow(0) or tableView.selectRow(2) won't work in this situation since selectRow() selects only single row deselecting all others.

There is selectionModel().select() method available. But it accepts QSelectionItems object as the argument. How do we declare the QSelectionItem object having the row numbers?


Solution

  • You should set the selection mode.

    tableView->setSelectionMode(QAbstractItemView::MultiSelection);