PyQt6 QAction menu/setMenu?
Maurizio Berti
maurizio.berti at gmail.com
Mon Jul 18 07:19:15 BST 2022
Based on Matic's post on StackOverflow (
https://stackoverflow.com/q/72943053/2001654), I believe I can understand
the reason for this: having a custom QWidgetAction that *also* acts as an
item for a submenu.
I realize this is quite a "fringe" case, but it also seems reasonable.
For instance, imagine a group of non-exclusive checkable actions, and you
have a menu that has a submenu for that group (without overflowing the
parent menu), with its action item that is also able to show that "some"
actions in that group are checked. As we know, QActions don't support
partially checked states, so the only available option (yet) is to use a
QWidgetAction.
There are other cases that would require this, and (but, please, tell me if
I'm terribly wrong) the setMenu is still the easier solution.
While it's possible to override QMenu/QStyle to do so, it seems a bit of an
overshoot: what to do with dynamic menus? What if I just want to add an
action to an existing menu (such as the standard menu created for text
widgets)? What if the menu was created in Designer (yes, I know, promoted
widgets, but... is it really necessary for something like this?)
As stated in the (controversial) discussion of the answer to that post, I
agree that the main problem possibly resides in Qt, which should bring back
that feature in some way. Still, as far as I can understand, it's also
available through the C++ API, so currently the problem is the
implementation in the binding.
Maurizio
PS: I don't know if the author of the answer to that post is reading this;
if you are, I want to remark that there was absolutely no bad
intention/critic to your answer, it was just a sane discussion between
people who may *just* disagree, without any judgment, no personal grudge,
nor even any assumption or prejudice on knowledge or experience.
Il giorno dom 17 lug 2022 alle ore 20:02 Dmitry Shachnev <mitya57 at ubuntu.com>
ha scritto:
> Hi all,
>
> On Sun, Jul 17, 2022 at 11:02:20AM +0100, Phil Thompson wrote:
> > On 12/07/2022 17:55, Matic Kukovec wrote:
> > > Hi Phil,
> > >
> > > In Qt5 there were QAction::menu/QAction::setMenu methods for setting a
> > > menu on an action,
> > > but in Qt6 these are templates. Could there be a workaround for this in
> > > PyQt6?
> > > PySide seems to have done it:
> > > https://bugreports.qt.io/browse/PYSIDE-1627
> >
> > This comes up from time to time but not with any sense of urgency which
> > suggests to me that there is another way of doing things - particularly
> as
> > those methods were deprecated in Qt v6.0.
>
> For actions in a menu, one can simply use a nested QMenu and addMenu
> method.
>
> For actions in a toolbar, one can use QToolButton which has setMenu method
> (working in PyQt6).
>
> --
> Dmitry Shachnev
>
--
È difficile avere una convinzione precisa quando si parla delle ragioni del
cuore. - "Sostiene Pereira", Antonio Tabucchi
http://www.jidesk.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20220718/75da0ab0/attachment.htm>
More information about the PyQt
mailing list