首页 > 解决方案 > 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?

标签: qtcelleditingqtablewidget

解决方案


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

推荐阅读