I still don't get it :-D All I get is nullptrs ... Maybe I'm missing the forest for the trees?!
I now attached a minimal example showing my dilemma. After having put demoui.rc to ~/.local/share/kxmlgui5/demo/, the GUI is setup nicely and all, but how do I get a pointer to the "subMenu" menu? To e. g. assign an icon to it's action or to disable the whole menu?! Am Mittwoch, 13. Januar 2021, 14:58:25 CET schrieb Ismael Asensio: > Once you have the main QAction, it has a menu() method, which in turn has > an actions() method. > > So for instance: > bar = foo->menu()->actions().at(0). > > Of course with much more logic to check that every item exists and not > hardcoding the position, but I hope you get the point.
cmake_minimum_required(VERSION 3.8.0) project(demo CXX) find_package(ECM 1.1.0 REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake) find_package(Qt5 5.11 COMPONENTS Widgets REQUIRED) find_package(KF5 COMPONENTS XmlGui REQUIRED) set(CMAKE_AUTOMOC ON) add_executable(demo ${CMAKE_SOURCE_DIR}/main.cpp) target_link_libraries(demo Qt5::Widgets KF5::XmlGui)
demoui.rc
Description: application/vnd.kde.kxmlguirc
#include <QApplication> #include <KXmlGuiWindow> #include <KActionCollection> class MainWindow : public KXmlGuiWindow { Q_OBJECT public: explicit MainWindow() { auto *topMenuAction = actionCollection()->addAction("topMenuAction"); topMenuAction->setText("Some top menu action"); topMenuAction->setIcon(QIcon::fromTheme("document-new")); auto *subMenuAction = actionCollection()->addAction("subMenuAction"); subMenuAction->setText("Some sub menu action"); subMenuAction->setIcon(QIcon::fromTheme("document-open")); // How do I get a pointer to the "subMenu" menu? // To e. g. assign an icon to it's action or to disable the whole menu?! KStandardAction::quit(this, &QWidget::close, actionCollection()); setupGUI(Keys | Save | Create, "demoui.rc"); } }; int main(int argc, char *argv[]) { QApplication app(argc, argv); auto *mainWindow = new MainWindow; mainWindow->show(); return app.exec(); } #include "main.moc"