user1590232
user1590232

Reputation:

QAction parent menu

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?

Upvotes: 0

Views: 1558

Answers (1)

Alexander Tyapkov
Alexander Tyapkov

Reputation: 5017

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

ui->action567->associatedWidgets();

Upvotes: 2

Related Questions