• _images/menu.tpi.0d9ce6b04d.png

    A menubar

  • _images/menu-disabled.tpi.53899405ca.png

    in disabled state

  • _images/menu-submenu.tpi.ce9458211b.png

    with submenu open

A menu bar allows users to browse and select from a fairly big number of commands. It is a classic user interface element to enable users to discover and use functionality of an application without having to read the manual. For faster access on repeated use, often menu items additionally display a keyboard shortcut that also allows accessing the command.

Usually applications have a global menu bar that is almost always reachable. The menu bar can be activated by pressing F10 or by pressing Alt in combination with one of the the highlighted characters on the menu bar. The menu can then be navigated using the cursor keys and a command selected using Enter or by pressing the highlighted character (this time without using Alt as modifier) 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::ZMenubar::setItems(QVector<Tui::ZMenuItem> items). Currently only menu bar entries and one level of sub-menus are supported.

See also: ZMenuItem, ZMenu


Tui::ZMenubar *menubar = new Tui::ZMenubar(root);

QVector<Tui::ZMenuItem> items = {
    { "<m>F</m>ile", "", {}, {
        { "<m>N</m>ew", "", "NewFile", {}},
        { "<m>O</m>pen", "", "OpenFile", {}},
        { "<m>S</m>ave", "", "SaveFile", {}},
        { },
        { "<m>Q</m>uit", "Ctrl-q", "Quit", {}},
    { "<m>H</m>elp", "", {}, {
        { "<m>A</m>bout", "", "AboutDialog", {}}


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

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

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


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

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

Keyboard Usage





application shortcut

Activate the menu bar

Alt + (setup mnemonic)

application shortcut
active menu bar

Activate/Open the menu item

active menu bar

Cycle through menu items / sub-menus left

active menu bar

Cycle through menu items / sub-menus right


active menu bar

Close the menu


active menu bar

Close the menu


active menu bar

Active the current menu item

active sub-menu

Cycle through menu items up

active sub-menu

Cycle through menu items down

(highlighted letter)

active sub-menu

Active the menu item with the corresponding letter


The menu bar does not accept focus and is one cell high and has a expanding vertical layout policy. The size request of a menu bar is calculated from the width of the top level menu items.

The menu bar ensures that its parent widget has a command manager by calling ensureCommandManager() on its parent and then bind to it to track command status changes and reflect them to the top-level menu item’s shortcuts.

It setups F10 as an application context shortcut to activate the menu. For the mnemonic letters of the top level menu items it similarly creates application context shortcuts to activate them (possibly showing their sub items as sub-menu).

When activated the menu bar grabs the keyboard. It then allows the user to browse the menu and activate the menu items. If a top level menu item has sub items it will create a browsable sub-menu (using Tui::ZMenu). The keyboard grab is transfered between the menu bar and sub-menus as needed.


Palette Color



Main color for the menu


Shortcut character in menu items, menu.selected.fg

Selected menu items


Shortcut character in selected menu items


Menu items with disabled command or disabled menu bar


Selected menu items with disabled command


class Tui::ZMenubar : public Tui::ZWidget

A menu bar widget.


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

The menu items to display in the menu.

The items can contain nested items lists to support sub-menus. Currently only menu bar entries and one level of sub-menus are supported.

void keyActivate(Tui::ZKeyEvent *event)

Used by sub-menus to implement Alt + mnemonic handling.


void left()

Used by sub-menus to implement .

void right()

Used by sub-menus to implement .

void close()

Close any open sub-menu and deactivate the menu bar.