gornvix
gornvix

Reputation: 3374

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?

Upvotes: 3

Views: 4082

Answers (2)

ekhumoro
ekhumoro

Reputation: 120578

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());

Upvotes: 4

Mohammad Kanan
Mohammad Kanan

Reputation: 4582

You can grap a QTableWidgetItem from the selection you made, and pass it to QTableWidget::editItem(QTableWidgetItem);

ui->tableWidget->editItem(ui->tableWidget->currentItem());

Upvotes: 0

Related Questions