QAction parent menu

ぃ、小莉子 提交于 2019-12-12 02:38:57

问题


How to get parent menu of a given QAction? I have a QActions added to submenus.

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

ui->action567->parent() //return MainWindow
ui->action567->parentWidget() //return MainWindow
ui->action567->menu() //return nullptr.
ui->action567->actionGroup() //return nullptr.

I can get parent menu this way:

for( QMenu * menu : ui->menuBar->findChildren< QMenu * >() )
{
    if( menu->actions().contains( ui->action567 ) )
    {
        qDebug() << menu << ui->action567 ;
        break;
    }
}

Does better and more native way exists?


回答1:


associatedWidgets() will return you a list of widgets this action was added to.

ui->action567->associatedWidgets();


来源:https://stackoverflow.com/questions/32006039/qaction-parent-menu

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!