Accessing a (sub)menu defined in an XmlGui ui.rc file

Tobias Leupold tobias.leupold at gmx.de
Wed Jan 13 21:48:55 GMT 2021


Hi Alexander :-)

This actually works! It has to be done after having called setupGUI(), just to
notice this, otherwise, one still gets a nullptr.

What I did in the example I wrote before:

    #include <KXMLGUIFactory>
    #include <QMenu>

    ...

    setupGUI(Keys | Save | Create, "demoui.rc");

    auto *guiFactory = this->guiFactory();
    auto *subMenu = dynamic_cast<QMenu *>(
        guiFactory->container("subMenu", this));
    subMenu->menuAction()->setIcon(QIcon::fromTheme("document-save-all"));

    ...

I really tried hard to read the docs. And I really searched! But honestly,
there's no way to grasp this (for somebody not having worked with this for
ages or so). This should be either mentioned somewhere in a tutorial/howto or
some more intuitive way to get a menu pointer should be available imo ...

At least, the mailing list archive now knows this, so that possibly, one will
be able to find this when googling it later.

Thanks a lot :-)

Tobias

Am Mittwoch, 13. Januar 2021, 21:18:57 CET schrieben Sie:
> Hi Tobias,
>
> > 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 ...
> > [...]
> > 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,
>
> In your main window class deriving from KXMLGuiWindow you do the following:
>
> auto* factory = this->guiFactory();
> auto* menu = dynamic_cast<QMenu*>(factory->container("bar", this));
> if (menu) {
>     //add your logic here with the menu pointer
> }
>
> Is this what you're looking for?
>
> --
> Alexander






More information about the kde-devel mailing list