A popup menu is a menu presented in a popup window. The menu implements a
typical context menu, with support for submenu's.
WPopupMenu is not to be confused with
WMenu which implements an always-visible
navigation menu for a web application.
When initially created, the menu is invisible, until popup() or
exec() is called. Then, the menu will remain visible until an
item is selected, or the user cancels the menu (by pressing the Escape
key or clicking elsewhere).
The implementation assumes availability of JavaScript to position the
menu at the current mouse position and provide feed-back of the currently
selected item.
WPopupMenu is similar in use to
WDialog. So there are two ways of using
the menu. The simplest way is to use one of the exec() methods,
apply a reentrant event loop and wait until the user selected an item or
cancelled the popup menu (by pressing Escape or clicking elsewhere).
Preferably, use one of the popup() methods to show the menu and
listen to the aboutToHide signal where you read the
result() (the last triggered menu item). If you listen to the
aboutToHide signal of a parent popup it will also be triggered
by its child popups.
You have several options to react to the selection of an item:
You can use the WMenuItem itself to identify the action,
perhaps by specialization or by simply by binding custom data using
WMenuItem::setData().
You can use a lambda function to connect to each of the listeners.
In C++, you can use boost::bind() to bind parameters that identify the
selected item.
You can bind a separate method to each item's
WMenuItem::triggered signal.