Skip to content
Advertisement

Qt.CheckState.Checked != 2 and Qt.CheckState.Checked != 0

The PyQt6 documentation says that Qt.CheckState.Unchecked == 0 and Qt.CheckState.Checked == 2.

I wrote a little program to test this, but the result is completely different.

Here is the program code:

JavaScript

But when I click on the checkbox, the following is displayed:

JavaScript

Why?

Advertisement

Answer

The problem is that you are comparing an int(the value sent by the stateChanged signal) and an enum(Qt.CheckState.Unchecked) so it cannot be compared directly. The solution is to convert the integer to enum:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement