QT: How to prevent changing the contents of a QTableWidget

2

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.

    
asked by anonymous 18.07.2015 / 20:30

1 answer

1

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.

    
18.07.2015 / 20:32