How to know parent menu of a given QAction?

前端 未结 1 1539
感动是毒
感动是毒 2021-01-24 01:46

I have a list of QActions, some are added to the top level menu and few are added to submenus of top level.

Is there any way to know parent menu name of each actions?

相关标签:
1条回答
  • 2021-01-24 02:48

    You can check if the result of act->parentWidget() if it is a valid pointer, if so you can manipulate as a normal widget.

    To get the menu name, it depends on which widget you are using.

    If is QMenu, you can retrieve the menu title via the title function.

    QAction *act;
    ...
    QWidget *widget = act->parentWidget();
    if (widget) {
        QMenu *menu = dynamic_cast<QMenu*>(widget);
        menu->title();
    }
    
    0 讨论(0)
提交回复
热议问题