Class WPopupMenu


  • public class WPopupMenu
    extends WMenu
    A menu presented in a popup window.

    The menu implements a typical context menu, with support for submenu's. It is a specialized WMenu from which it inherits most of the API.

    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 hitting Escape 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.

    As with WDialog, there are two ways of using the menu. The simplest way is to use one of the synchronous exec() methods, which starts a reentrant event loop and waits until the user cancelled the popup menu (by hitting Escape or clicking elsewhere), or selected an item.

    Alternatively, you can use one of the popup() methods to show the menu and listen to the triggered() signal where you read the getResult(), or associate the menu with a button using WPushButton#setMenu().

    You have several options to react to the selection of an item:

    Usage example:

    
     // Create a menu with some items
     WPopupMenu popup = new WPopupMenu();
     popup.addItem("icons/item1.gif", "Item 1");
     popup.addItem("Item 2").setCheckable(true);
     popup.addItem("Item 3");
     popup.addSeparator();
     popup.addItem("Item 4");
     popup.addSeparator();
     popup.addItem("Item 5");
     popup.addItem("Item 6");
     popup.addSeparator();
    
     WPopupMenu subMenu = new WPopupMenu();
     subMenu.addItem("Sub Item 1");
     subMenu.addItem("Sub Item 2");
     popup.addMenu("Item 7", subMenu);
    
     WMenuItem item = popup.exec(event);
    
     if (item != null) {
     // ... do associated action.
     }
    
     

    A snapshot of the WPopupMenu:

    WPopupMenu example (default)

    WPopupMenu example (polished)

    See Also:
    WMenuItem