ZMenuItem¶
Menu items are used by Tui::ZMenubar and Tui::ZMenu.
A common way to create a menu structure using C++ initializer lists is:
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", {}}
}}
};
-
class Tui::ZMenuItem¶
This class is copyable and movable. It does not define comparison operators.
A menu item for use with
Tui::ZMenubarandTui::ZMenu.Constructors
-
ZMenuItem()¶
Constructs a menu item without text and command.
If left in this state the item represents a separator.
Tui::ZMenuand sub-menus inTui::ZMenubardisplay separators as a horizontal line dividing the menu in multiple parts.
-
ZMenuItem(const QString &markup, const QString &fakeShortcut, Tui::ZImplicitSymbol command, QVector<Tui::ZMenuItem> subitems)¶
Constructs a menu item and sets its data.
This is a short form that has the same result as calling
void setMarkup(const QString &markup),void setFakeShortcut(const QString &fakeShortcut),void setCommand(const Tui::ZImplicitSymbol &command)andvoid setSubitems(const QVector<Tui::ZMenuItem> &subitems)with the passed parameters.
-
ZMenuItem(const QString &markup, QObject *context, std::function<QVector<Tui::ZMenuItem>()> subitemsGenerator)¶
Constructs a menu item and sets its data.
This is a short form that has the same result as calling
void setMarkup(const QString &markup)andvoid setSubitemsGenerator(QObject *context, std::function<QVector<Tui::ZMenuItem>()> subitemsGenerator)with the passed parameters.
Functions
-
void setFakeShortcut(const QString &fakeShortcut)¶
This property represents the text that is displayed as shortcut in the menu item.
The menu system does not by itself arrange for the shortcut to be bound to the command of the item. Use a
Tui::ZShortcutto actually make the shortcut work.
-
const Tui::ZImplicitSymbol &command() const¶
-
void setCommand(const Tui::ZImplicitSymbol &command)¶
The command this menu item binds to.
The disabled state of the menu item will be the same as that of the command. If the menu item is activated this command will be activated.
-
void setSubitemsGenerator(QObject *context, std::function<QVector<Tui::ZMenuItem>()> subitemsGenerator)¶
-
bool hasSubitems() const¶
If a menu item has a non empty list of sub items it is a sub menu.
Currently sub-menus are only supported in
Tui::ZMenubarand may not nest.For some menu items the available sub items are highly dynamic, thus using a sub item generator function allows the application to generate the list of sub items on demand.
hasSubitemsreturns if sub items defined either as static list or generator are currently available.
-
ZMenuItem()¶