ZMenu

  • _images/menue-popupmenu.tpi.ed4b6f2adb.png

    A popup menu

ZMenu can be used to create popup menus. A popup (or context) menu can be used to offer multiple action related to the currently selected item.

After the menu is opened, it can then be navigated using the cursor keys and a command selected using Enter or by pressing the highlighted character or the menu can be left using Esc.

The menu system uses commands to determine if a menu item is currently available and to trigger an action if the user activates a menu item.

The application must setup the menu with a collection of menu items to gain a functional menu using void Tui::ZMenu::setItems(QVector<Tui::ZMenuItem> items). Currenty sub-menus are not supported.

The menu is usually created with the root widget as parent and opened by using the void Tui::ZMenu::popup(const QPoint &p) function.

See also: ZMenuItem, ZMenubar

Example

QVector<Tui::ZMenuItem> items =  {
    {"Kilo", "", "kilo", {}},
    {"Mega", "", "mega", {}},
    {"<m>G</m>iga", "", "giga", {}},
    {"Tera", "", "tera", {}},
    {},
    {"Peta", "", "peta", {}},
    {"Exa", "", "exa", {}},
    {"Zetta", "", "zetta", {}},
    {"Yotta", "", "yotta", {}}
};

Tui::ZMenu *menu = new Tui::ZMenu(root);
menu->setItems(items);

QObject::connect(new Tui::ZCommandNotifier("mega", root), 
                 &Tui::ZCommandNotifier::activated, [&] { /* ... */ });

QObject::connect(new Tui::ZCommandNotifier("giga", root),
                 &Tui::ZCommandNotifier::activated, [&] { /* ... */ });

QObject::connect(new Tui::ZCommandNotifier("tera", root),
                 &Tui::ZCommandNotifier::activated, [&] { /* ... */ });

menu->popup({1, 1});

Keyboard Usage

Key

Result

Esc

Close the menu

F10

Close the menu

Enter

Active the current menu item

Cycle through menu items up

Cycle through menu items down

(highlighted letter)

Active the menu item with the corresponding letter

Behavior

The menu uses stacking layer 20000 by default and acts like a window with extend viewport enabled.

The menu ensures that its parent widget has a command manager by calling ensureCommandManager() on its parent.

When activated the menu bar grabs the keyboard. It then allows the user to browse the menu and activate the menu items.

(ZMenu does not support use as popup menu when disabled)

Palette

Palette Color

Usage

menu.fg, menu.bg

Main color for the menu

menu.shortcut.fg, menu.shortcut.bg

Shortcut character in menu items

menu.selected.bg, menu.selected.fg

Selected menu items

menu.selected.shortcut.fg, menu.selected.shortcut.bg

Shortcut character in selected menu items

menu.disabled.fg, menu.disabled.bg

Menu items with disabled command or disabled menu bar

menu.selected.disabled.fg, menu.selected.disabled.bg

Selected menu items with disabled command

ZMenu

class Tui::ZMenu : public Tui::ZWidget

A popup menu widget.

Functions

void setItems(QVector<Tui::ZMenuItem> items)
QVector<Tui::ZMenuItem> items() const

The menu items to display in the menu.

Currently sub-menus are not supported.

void setParentMenu(Tui::ZMenubar *menu)

Used by Tui::ZMenubar to implement its sub-menus.

void popup(const QPoint &p)

Open this popup menu at the given point.

This grabs the keyboard and displays the menu with an automatic size and a position based on p.

Signals

void aboutToHide()

This signal is emitted just before the popup menu is hidden on close.

void aboutToShow()

This signal is emitted just before the popup menu is shown.