Flags: object cannot be interpreted as an integer
-
Hi,
I have been trying to set some flags for my widget, but seems to be running into issue on my Mac. I'm not sure if this is a Mac specific issue:
# code to make item in a ListWidget non selectable list_item.setFlags(list_item.flags() & ~Qt.ItemIsSelectable) # Error: TypeError: 'PySide2.QtCore.Qt.ItemFlags' object cannot be interpreted as an integer
I'm getting the same error when setting WindowFlags and WindowTypes. Is this a MacOS specific issue or python specific issue?
-
Using
and
instead of&
fixed my issue. Might have been issue with a later version of PySide. -
I see! Although most of the references I found online all use
setFlags
(e.g. https://forum.qt.io/topic/64392/how-can-i-setflags-as-i-setitem/2).AttributeError: 'PySide2.QtWidgets.QListWidgetItem' object has no attribute 'setFlag'. Did you mean: 'setFlags'?
If
& ~
is not the right way to disable a flag in python, what is the right way? -
Using
and
instead of&
fixed my issue. Might have been issue with a later version of PySide. -
-
For setFlag, it's a method of the QFlags class.
-
@sophia73583 said in Flags: object cannot be interpreted as an integer:
Using
and
instead of&
fixed my issue. Might have been issue with a later version of PySide.It might have fixed the error but I am surprised/you seem lucky it gives you the correct behaviour. In Python
&
is bit-wise AND, which ought be wanted here, while theand
you are now using is logical True/False result.