PyQt6: Missing QAction.setMenu or equivalent

Dmitry Shachnev mitya57 at ubuntu.com
Wed Apr 21 19:47:16 BST 2021


On Wed, Apr 21, 2021 at 02:26:59PM -0400, RoadrunnerWMC wrote:
> That'd work in that particular case, but it's still a problem that there's
> (as far as I know) no way to implement the following common pattern in
> PyQt6:
>
> recent_menu = QtWidgets.QMenu()
> recent_menu.addAction('foo.py')
> recent_menu.addAction('bar.txt')
> recent_menu.addAction('baz.png')
>
> menu = main_window.menuBar().addMenu('&File')
> menu.addAction('Open...')
> menu.addAction('Open Recent').setMenu(recent_menu)

I think you can use:

recent_menu = QtWidgets.QMenu('Open Recent')

and then simply:

menu.addMenu(recent_menu)

--
Dmitry Shachnev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20210421/7db733b6/attachment.sig>


More information about the PyQt mailing list