Search code examples
pythonpyqtqtableview

How do you selcet the specific cell in a QTableView


In Python, using a QTableView how do I get a specific cell and how do I set the current cell.


Solution

  • To get a specific cell from the QTableView aka "index" use:

    e.g. for cell[0,0]

    m = self.tbl.model()
    itm = m.index(0, 0)
    

    and to set a current position use the position you got above

    sm = self.tbl.selectionModel()
    sm.setCurrentIndex(itm, QItemSelectionModel.SelectionFlag.ClearAndSelect)