This forum has been archived. All content is frozen. Please use KDE Discuss instead.

How can I access a menuAction for a menu created by KXmlGui?

Tags: None
(comma "," separated)
User avatar
l3u
Registered Member
Posts
38
Karma
0
OS
Hi all :-)

Apparently, a submenu can be added to an ...ui.rc file like so:
Code: Select all
<MenuBar>
  <Menu name="foo" >
    <Menu name="bar">
      <text>Some text</text>
      <Action name="someAction"/>
    </Menu>
  </Menu>
</MenuBar>

I can access the actions defined like so:
Code: Select all
auto *someAction = actionCollection()->addAction(QStringLiteral("someAction"));
someAction->setText(i18n("Some action"));
someAction->setIcon(QIcon::fromTheme(QStringLiteral("some-icon")));

But how can I access the "bar" menu's menu action to assign an icon and/or enable or disable the menu? And can the menu's text also be set programatically (using the menu action) or do I have to define the translatable string in the ui.rc file?

Thanks in advance!

Cheers, Tobias
User avatar
l3u
Registered Member
Posts
38
Karma
0
OS
Thanks to the kde-devel mailing list (thanks a lot Alexander Semke!), I can finally answer this myself:

After having called
Code: Select all
setupGUI()

It's possible to get a pointer to a menu like so:
Code: Select all
auto *someMenu = qobject_cast<QMenu *>(guiFactory()->container("menuId", this));

To do things like that:
Code: Select all
someMenu->menuAction()->setIcon(QIcon::fromTheme("document-save-all"));
eduardosv
Registered Member
Posts
6
Karma
0


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]