QT: How to prevent changing the content of a Qtablewidget

Asked

Viewed 156 times

2

The title of the question says it all: How can I prevent editing a particular column of a QTableWidget?

I have already done some research and I think the solution is to use a few flags, but I couldn’t come up with a solution.

1 answer

1


It’s very simple, and as you say in the question the solution is to use flags. To deactivate the editing mode just do:

QTableWidgetItem *item = new QTableWidgetItem();
item->setFlags(item->flags() & ~Qt::ItemIsEditable);

This alternative has the advantage of not altering the behaviour of others flags only that of 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 the XOR to play a switch role: each time it is executed it toggles the edit according to the current state.

  • 1

    It was worth the force! once again! :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.