PyQt6 QAction menu/setMenu?

Matic Kukovec kukovecmatic at hotmail.com
Tue Jul 19 16:07:52 BST 2022


From: Phil Thompson <phil at riverbankcomputing.com>
Sent: Tuesday, July 19, 2022 4:21 PM
To: ekhumoro <ekhumoro at gmx.com>
Cc: pyqt at riverbankcomputing.com <pyqt at riverbankcomputing.com>
Subject: Re: PyQt6 QAction menu/setMenu?

On 18/07/2022 11:31, ekhumoro wrote:
> On 18/07/2022 07:19, Maurizio Berti wrote:
>> 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.
>
> That is one genuine use-case. But the more general problem is: how to
> set a menu on a *subclass* of QAction? AFAICS,
> this is currently impossible without QAction.setMenu(), since none of
> the other APIs will preserve the type. For example:
>
>     submenu = QMenu()
>     action = QMenu.addMenu(submenu)
>
> just returns a plain QAction via QMenu.menuAction(), which is
> read-only. ISTM that Qt has deprecated an API without
> first providing an alternative code path. The Qt docs strongly advise
> against using setMenu() in new code, but for some
> genuine use-cases there really is no alternative. Or at least, I can't
> see one - please someone correct me if I am wrong!
>
> It was suggested in Qt code review that something like
> QMenu.setMenuInAction() might be added at some point - which
> *would* solve the problem. But what are users supposed to do in the
> meantime? For anyone porting from [Py]Qt5 who has an
> extensive menu system based on subclasses of QAction, this issue seems
> to be a significant blocker.

I decided it would be quicker to implement menu() and setMenu() than to
work out whether they were really needed.

Phil
​Excellent, thank you 👍👍👍

Regards,
Matic
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20220719/2eea3ec3/attachment-0001.htm>


More information about the PyQt mailing list