From kde-devel Wed Jan 13 10:25:18 2021 From: Thomas Baumgart Date: Wed, 13 Jan 2021 10:25:18 +0000 To: kde-devel Subject: Re: Accessing a (sub)menu defined in an XmlGui ui.rc file Message-Id: <5679583.UjTJXf6HLC () thb-nb> X-MARC-Message: https://marc.info/?l=kde-devel&m=161053355129267 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--nextPart9710700.0AQdONaE2F" --nextPart9710700.0AQdONaE2F Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" On Mittwoch, 13. Januar 2021 10:39:48 CET Tobias Leupold wrote: > Hi list :-) > > I have a problem with a KXmlGuiWindow and I honestly can't find respective > docs or howtos/tutorials. I hope someone here can help me ... > > It's a allegedly basic task: How can I access a submenu (or better: a > submenu's QAction) for a menu defined in a ...ui.rc file? > > If I define the submenu like so: > > > > > Some text > > > > > > I can access the "someAction" action like the other ones like so: > > auto *someAction > = actionCollection()->addAction(QStringLiteral("someAction")); > someAction->setText(i18n("Some action")); > someAction->setIcon(QIcon::fromTheme(QStringLiteral("some-icon"))); > connect(someAction, &QAction::triggered, this, > &SomeClass::someFunction); > > and so on. > > But how can I get the "bar" QMenu (or it's respective QAction)? So that I > can > e. g. disable or hide the menu, or assign an icon? For manually defined > menus, > this would be as easy as "auto *action = menu->menuAction();" ... Here's how it is done in KMyMoney (may not be the best way, but it's working): https://invent.kde.org/office/kmymoney/-/blob/master/kmymoney/kmymoney.cpp#L1270 creates all the menus during initialization. The QStringLiterals contain the names used in the xmlgui.rc file. KMyMoneyApp is derived from KXmlGuiWindow and thus provides the factory() method. The actions need to exist before the menu is initialized from what I see. All this is called before setupGUI() is executed. The context menu can then be executed by e.g. lutMenus[Menu::Institution]->exec(QCursor::pos()); Hope that helps and gives you some ideas. -- Regards Thomas Baumgart https://www.signal.org/ Signal, the better WhatsApp ------------------------------------------------------------- Idle servers are the devil's work -- robbyoconnor on #irc ------------------------------------------------------------- --nextPart9710700.0AQdONaE2F Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- Comment: http://www.net-bembel.de/ iQIzBAABCgAdFiEEldM0sAUOY2HYD2VASQpC8iaztXcFAl/+yo4ACgkQSQpC8iaz tXdfzhAA3iNhOJdhbpWcRymVJNb7LZcuVKMWCAUOeV5x7/eHktnnOE+ks8A7QiuN asUKfvVELinLawcvsRsP2NFz5HcvgV90YBMRVwPHwFH3QJoRZadka888g0LoE+ND enCUJhCkQcXrjwe2Lwk1SuPetwI9PY083ZaY5Z0sbh7OMkDh8cdFnvoHlzaiW8fq qXSMqaZMk4V+Yy6RIvydizziUfqVy6jyzZ2oxTpCE+3WCTzmul784jw6LaWhzCuP JVUceZyQqZGODMwnxVkIGQ0EwCwmD4ZSncBIzfJK6TecryA6orzWZjCK0QNt9ZuP j1tIoQr6VSY2/NRrukfvTMAXKaLMF3gqAydYH+/rd0PKduiNRro6gMaLYpHyjRq6 w7A6+u1xZcisIdH8NYxdE0Im6lcT3A/avJq9KYFP6q7010N/V9Se1tneAop2MvWw 4EjHY4GSDo3utsIAyTcANb0lmKTZam+x2+YXvnZ4l89TL1uqWhakCHybZXQNUZAm V6Y33aCT2mQU6c8dVoUm6Gz5efWVhGPJfhrExskE8TM/+YEOebwWxvLrtTxwLTWc I5TCsB/JiY4tdMNFE0f0/dbj6+wZOQY9dzTtK+o0Q/RkItfyz2ZAUhXwBhsOi3kk fOO8mPnE5VvyRQ9JHI/CnNmiT5h0nnG/oyhwx6cmxzGpeTW9nFE= =rShj -----END PGP SIGNATURE----- --nextPart9710700.0AQdONaE2F--