The title of the question says it all: How can I prevent editing a given column from a QTableWidget
?
I've been researching and I think the solution involves using some flags , but I could not come up with a solution.
The title of the question says it all: How can I prevent editing a given column from a QTableWidget
?
I've been researching and I think the solution involves using some flags , but I could not come up with a solution.
It's very simple, and as you say in the question the solution is to use flags . To disable the editing mode just do:
QTableWidgetItem *item = new QTableWidgetItem();
item->setFlags(item->flags() & ~Qt::ItemIsEditable);
This option has the advantage of not changing the behavior of other flags only the flag Qt::ItemIsEditable
There are other alternatives, such as:
QTableWidgetItem *item = new QTableWidgetItem();
item->setFlags(item->flags() ^ Qt::ItemIsEditable);
The latter makes use of XOR to play a switching role: each time it is run on or off the edition according to the current state.