I am trying to make an if condition on whether the flag 'ItemIsMovable' of a QGraphicsItem is enabled.
Ideally something like:
import PyQt5.QtWidgets as qtw
item = PyQt5.QtWidgets.QGraphicsRectItem(1, 1, 10, 10)
if 'ItemIsMovable' in item.flags():
do things ...
Here I am using the method QGraphicsItem::flags()
that returns the object QGraphicsItem::GraphicsItemFlags
which I don't know what to do with: it has no attributes, no methods.
I have read the Qt documentation and I could not find a method that tells me if a specific flag is enabled or not. I was looking for a function like QGraphicsItem::isFlagEnabled(flag) --> bool.
I have tried to iterate over QGraphicsItem::GraphicsItemFlags
but I get the error that it is not iterable.
Is there any way to get the status of a flag, enabled or disabled?
CodePudding user response:
Use bitwise operator "and" (&).
if item.flags() & QGraphicsItem.ItemIsMovable: