Heini
Heini

Reputation: 295

Create a QTableWidgetItem with flags()

I dont understand the Qt5 Documentation in the TableWidgetItem-Chapter. I cant get the right parameters to set my freshly created TableCell as editable. I've got this piece of code

for i, item in enumerate(event_desc, start=0):
        print(i, item)
        key   = QTableWidgetItem(list(event_desc)[i])
        value = QTableWidgetItem(event_desc[item])
        value.setFlags( * what's to insert here? * )
        tw.insertRow(i)
        tw.setItem(i, 0, key)
        tw.setItem(i, 1, value)

The first param should be *self, the 2nd one is named 'Union' (What does this mean? i cant go further, this param is missing)

Upvotes: 3

Views: 3084

Answers (2)

Rui
Rui

Reputation: 97

Additionally, if you use Pyside6 lib like me, the flag may be changed as,

Qt.ItemIsEditable or ~Qt.ItemIsEditable

Upvotes: 0

eyllanesc
eyllanesc

Reputation: 243975

If you must set a QTableWidgetItem as editable you must do:

value.setFlags(value.flags() | QtCore.Qt.ItemIsEditable)

The operator | allows to enable a flag, and instead the operation & ~ disables them.

Upvotes: 4

Related Questions