Bool of .checkState() is always True?
-
I have a QTableWidget with checkable items. In the last version of PySide I used (6.1.2) before what I updated to recently (6.4.0), taking bool() of .checkState() would return True/False depending on if the box is checked. Now it always returns True. I have tested this with
print(item.checkState()) print(bool(item.checkState())
And regardless of whether or not the first statement prints CheckState.Checked or CheckState.Unchecked, the second statement always prints True. Ideas?
-
I have a QTableWidget with checkable items. In the last version of PySide I used (6.1.2) before what I updated to recently (6.4.0), taking bool() of .checkState() would return True/False depending on if the box is checked. Now it always returns True. I have tested this with
print(item.checkState()) print(bool(item.checkState())
And regardless of whether or not the first statement prints CheckState.Checked or CheckState.Unchecked, the second statement always prints True. Ideas?
@somethingvague
What aboutprint(item.checkState() == Qt.Checked) # or print(item.checkState() != Qt.Unchecked)
[It's possible the
Checked/Unchecked
got moved out fromQt
namespace to a different one at Qt6.x, I don't know. Ah, yes, at PyQt6 you might find your need to useQt.CheckState.Checked
/Unchecked
?]The reason is probably something to do with https://stackoverflow.com/questions/72161415/qt-checkstate-checked-2-and-qt-checkstate-checked-0
-
@JonB said in Bool of .checkState() is always True?:
print(item.checkState() == Qt.Checked)
or
print(item.checkState() != Qt.Unchecked)These work for my purposes, but I am curious as to why the checkStates() can no longer be used as booleans. It was pretty convenient.
-
Take a look at
print(int(item.checkState())
I would guess ist not 0 - but according to the docs it should.
-
Take a look at
print(int(item.checkState())
I would guess ist not 0 - but according to the docs it should.
That results in the following error:
int() argument must be a string, a bytes-like object or a number, not 'CheckState'
-
That results in the following error:
int() argument must be a string, a bytes-like object or a number, not 'CheckState'
@somethingvague
...which somewhere along the line is the issue...
Now you would have to find out exactly howbool()
behaves in such a situation.
One thought: you didn't change your Python version between PySide 6.1.2 and 6.4.0 did you?
It's not clear to me whether this is an expected change or an inadvertent happenstance.
PySide6 (PyQt6?) may have been making more of an effort to separate off treating enumerated types from integers.