Important: Please read the Qt Code of Conduct -

How to remove a flag?

  • Hello,
    i am new to Qt or PyQt and have a very basic question.
    I have a Table Widget Item and I set a flag to it.

    table.item(0, 1).setFlags(Qt.ItemIsEnabled)

    Now the user can't interact with the cell of the table anymore.
    But now i want to remove this flag and allow the user to interact with the cell again. How do i do that?
    Thank you

  • @Moesen
    You can write this in Python as you would in C++:

    table.item(0, 1).setFlags(table.item(0, 1).flags() & ~Qt.ItemIsEnabled)

    As in C++, use | to "OR in" a flag and & ~ to "AND out" a flag.

    BTW, really you should have written table.item(0, 1).setFlags(table.item(0, 1).flags() | Qt.ItemIsEnabled). The way you did it with setFlags(Qt.ItemIsEnabled) will clear any other flags which might be set, whereas really you only want to set the enabled flag on top of whatever else might or might not already be there.

  • Thank you, this helped me so much!

  • @Moesen Please mark the thread as resolved!

Log in to reply