Flags: object cannot be interpreted as an integer
-
wrote on 13 Oct 2023, 22:58 last edited by
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?
-
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?wrote on 16 Oct 2023, 19:42 last edited byUsing
and
instead of&
fixed my issue. Might have been issue with a later version of PySide. -
Hi,
It has nothing to do with macOS rather Python.
While I can't check right now, one thing you can do in between is the use the setFlag method to disable the specific flag you want to remove.
-
Hi,
It has nothing to do with macOS rather Python.
While I can't check right now, one thing you can do in between is the use the setFlag method to disable the specific flag you want to remove.
wrote on 16 Oct 2023, 18:48 last edited byI 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? -
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?wrote on 16 Oct 2023, 19:42 last edited byUsing
and
instead of&
fixed my issue. Might have been issue with a later version of PySide. -
-
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.
-
Using
and
instead of&
fixed my issue. Might have been issue with a later version of PySide.wrote on 16 Oct 2023, 21:45 last edited by JonB@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.
5/6