Gambas Documentation - /comp/gb.qt4/menu

# Menu (gb.qt4)

This class represents a popup menu, or one element of a popup menu.

This class is
Creates a new menu.
creatable
.

Properties | Methods | Events
--- | --- | ---

Returns or sets the action string associated with the control.
Action
A synonymous for the Text property.
Caption
Indicates if a menu is checked.
Checked
Returns a collection of each child of the menu.
Children
Indicates if the menu is enabled.
Enabled
Returns or sets the name of the menu control.
Name
Returns or sets the icon displayed in the menu.
Picture
Return or set if a menu acts like a radio button.
Radio
Returns or sets the shorcut key name of the menu.
Shortcut
Returns or sets the tag associated with the menu.
Tag
Returns or sets the text displayed in the menu.
Text
Returns or sets if this Menu acts like a toggle.
Toggle
A synonymous for the Checked property.
Value
Indicates if the menu is visible.
Visible
Returns the Window this Menu belongs to.
Window

Deletes the menu.
Delete
Hides a menu.
Hide
Open the menu under the mouse, and waits until it is closed.
Popup
Shows the menu.
Show

Raised when the user clicked on the menu.
Click
This event is raised just after the menu has been hidden.
Hide
Raised just before the menu is shown.
Show

### Creating a popup menu.

A popup menu is built by creating a hierarchy tree of Menu objects.

- Each menu of the hierarchy having children becomes a sub-menu.

- Each leaf of the hirerachy tree becomes a menu entry.

- The root menu must be a top-level menu (see below).

### Top-level menus

To create a top-level menu, i.e. an entry in the menu bar, the window must be the parent object of the menu.

As soon as a window has at least one visible top-level menu, the window menu bar becomes visible. Otherwise, it is hidden.

The Unity desktop removes the menu bar from the application window to put it on the top desktop panel.

Alas, it does not work well on windows that are not top-level windows, but embedded windows (like the Workspace control does).

To workaround the problem, run the following code at the very beginning of your program:

    Application.Env["APPMENU_DISPLAY_BOTH"] = "1"

To create a contextual popup menu not visible on the menu bar, just set its Visible property to False.

### Menu entries

Menu entries are Menu objects having no child.

Note that Menu controls do not inherit the Control class, and they do not raise any event of the Control class.

The order of menu entries in its popup parent menu follows the order of the creation.

### Separators

If the Text property of a menu entry is void, then that menu entry is replaced by a separator.

Useless separators are automatically removed when the popup menu is shown.