How to select a cell in QTableWidget programmatically

Viewed 171

I have an object of QTableWidget. Whenever, I click on a cell of the table, it becomes blue. How can I make a cell blue, say the cell located at row 1 and column 1, programmatically.

1 Answers

You have to use the selectionModel:

row = 1
column = 1
index = table_widget.model().index(row, column)
table_widget.selectionModel().select(
    index, QItemSelectionModel.Select | ItemSelectionModel.Current
)
Related