How to display a QMenu on a QAction trigger

1.5k Views Asked by At

I Have a (QT) toolbar in my application which is populated by QAction objects, and one of the QActions has an associated menu. I would like to pop up that menu below the QActions' button when the action is triggered.

I have tried:

m_ui->action_NewDataType->menu()->show();

but this shows the menu on the left upper corner of the screen, instead of where I want it. How can I show the menu below the QAction button, nicely aligned to the edges of the button?

1

There are 1 best solutions below

0
On BEST ANSWER

problem solved:

 QWidget* w = m_ui->mainToolBar->widgetForAction(m_ui->action_NewDataType);
 m_ui->action_NewDataType->menu()->popup(w->mapToGlobal(QPoint(0, w->height())))