QAction.setMenu is deprecated, what is the recommended alternative?
-
I'm migrating a Python desktop application from Qt5 to Qt6 (i.e. from PySide2 to PySide6). The old code has some calls to
QAction.setMenu(...)
, which is not supported in the newer version, as I getAttributeError: 'PySide6.QtGui.QAction' object has no attribute 'setMenu'
when running the program.Although issue PYSIDE-1627 is about this, my understanding is that it is Python-specific. However, the general documentation also points out that this function is deprecated. While other functions discussed on that page come with remarks such as "use X in module Y instead",
setMenu
does not.I'd like to understand whether there is a plan for resolving it in the future versions of PySide, or if one is supposed to take another approach altogether.
-
I'm migrating a Python desktop application from Qt5 to Qt6 (i.e. from PySide2 to PySide6). The old code has some calls to
QAction.setMenu(...)
, which is not supported in the newer version, as I getAttributeError: 'PySide6.QtGui.QAction' object has no attribute 'setMenu'
when running the program.Although issue PYSIDE-1627 is about this, my understanding is that it is Python-specific. However, the general documentation also points out that this function is deprecated. While other functions discussed on that page come with remarks such as "use X in module Y instead",
setMenu
does not.I'd like to understand whether there is a plan for resolving it in the future versions of PySide, or if one is supposed to take another approach altogether.
What's your use-case?
You could replace yourQAction
with a "real"QMenu
or aQPushButton
... Most people often mistaken thatQAction
has no graphical interface (as you can imagine from the name "action").
Only if you place aQAction
in a menuBar or something like that, it creates a graphical representation of it.... using aQWidget
.... and most of the time... aQPushButton
.
I think they removed it, because it doesn't make too much sense and just causes confusion about whatQAction
really is.Edit:
My theory could be wrong... but to confirm:For example,
QPushButton::setMenu
is still legit :)) -
Thanks for your feedback! If I replace the
QAction
with aQPushButton
, I run into a problem later, where several actions are used in.addActions(...)
of a widget derived from QFrame.It is a rather big legacy application, and I have no full awareness of what it is doing, because I'm not porting my own code and I don't know what the end result ought to look like. Thus, I don't have the foresight to understand what other parts are affected if I change a thing.
So I was hoping someone could shed some light on
QAction.setMenu
, which would allow me to make progress by dealing with one piece of the puzzle at a time.