3

In my QMenuBar, I have several menus.

One of those menus has a QWidgetAction in it.

It shows up fine, but the problem is that once the user completes his input, I want the menu to disappear (as is the normal behavior for a classical QAction).

However, I am not sure on how to do that. In my QWidgetAction, there is a button the user presses when he is done; I can therefore bind to this button's clicked() signal.

In the slot, I tried to setFocus() an element outside the menu but the menu still doesn't disappear.

How to tell the menu to close itself when my users finish interacting with the QWidgetAction?

Thanks

houbysoft
  • 32,532
  • 24
  • 103
  • 156

1 Answers1

3

QMenu inherits QWidget, so calling yourMenu->hide() should do the work.

Hope this helps.

zkunov
  • 3,362
  • 1
  • 20
  • 17
  • Ah, this works. I thought I tried that, but I was mistakenly trying to hide() the QMenuBar instead of the QMenu. Thanks! – houbysoft Mar 15 '11 at 23:55
  • the only problem with this is if your menu is a sub-menu (or one of many sub-menus) as it will not hide the full menu tree. – Nicolas Holthaus Sep 28 '15 at 14:36