Accessing a (sub)menu defined in an XmlGui ui.rc file
Tobias Leupold
tobias.leupold at gmx.de
Thu Jan 14 10:02:54 GMT 2021
Hi David!
Thanks for the input! In my case, it was only about how to get a pointer to
a menu defined via XML. What Alexander wrote does this very job:
auto *someMenu = qobject_cast<QMenu *>(
guiFactory()->container("menuId", this));
(for the XML you wrote, calling this with "foo", would return a pointer to
the menu defined via '<Menu name="foo">'.
Am Mittwoch, 13. Januar 2021 23:53:20 CET schrieb David Hurka:
> On Wednesday, January 13, 2021 10:39:48 AM 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 ...
>
> I faced the same problem... :(
>
>> 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:
>>
>> <MenuBar>
>> <Menu name="foo" > ...
>
> I probably don’t understand properly what you need. But if you
> want to modify
> the action which contains the menu "bar", you could use KActionMenu.
>
> Change the ui.rc to:
>
> <MenuBar>
> <Menu name="foo" >
> <Action name="bar"/>
> </Menu>
> </MenuBar>
>
> then create a KActionMenu called "bar" in your
> KActionCollection, set its icon
> etc., and populate its menu.
>
> Of course this moves UI definition from ui.rc to C++ code, but
> it looks like
> you want to modify the menu at runtime.
>
>
>
>
More information about the kde-devel
mailing list