Search code examples
qtcelleditingqtablewidget

How to enable edit-mode on a specific cell in a QTableWidget?


I can go to a specific cell:

ui->tableWidget->setCurrentCell(ui->tableWidget->rowCount() - 1, 0);

But how do I put the cell into editor mode, so the user does not have to double click the cell to begin editing the contents?


Solution

  • The QTableWidget class inherits QAbstractItemView, which has the required APIs.

    You just need to get the relevant model index using currentIndex(), and then pass that to the edit() slot to put the current cell into edit-mode:

    ui->tableWidget->edit(ui->tableWidget->currentIndex());