Hi everybody,

if you have a QMenuBar and you want a QMenu to popup without worrying about its position, you can write this code, assuming mb as a QMenuBar:

Qt Code:
  1. mb->setActiveAction(mb->actions()[0]);
  2.  
  3. mb->actions()[0]->menu()->setActiveAction(mb->actions()[0]->menu()->actions()[0]);
To copy to clipboard, switch view to plain text mode 

the first statemet makes the QMenu popup and the second one makes the first QAction be selected.

But if you want to close the opened QMenu, what would you do ?

Qt Code:
  1. mb->actions()[0]->menu()->setActiveAction(0);
To copy to clipboard, switch view to plain text mode 
works properly because it removes the selection on the first QAction of the QMenu

but

mb->setActiveAction(0);
doesn't work because the QMenu remains opened.

What would you do to make it disappear ?

Thanks
Placido.