[ fromfile: menus.xml id: menus ]
A QMenu is a QWidget that provides a particular kind of view for a collection of QAction
s.
A QMenuBar is a collection of menus, usually found in a QMainWindow.
When the parent of a QMenu is a QMenuBar, the QMenu appears as a pull-down menu with a familiar interface.
When its parent is not a QMenuBar it can pop up, like a dialog, in which case it is considered a context menu[48].
A QMenu can have another QMenu as its parent, in which case it becomes a submenu.
To help the user make the right choice, each QAction can have the following:
Text and/or icon that appears on a menu and/or button
An accelerator, or a shortcut key
A "What's this?" and a tool-tip
A way to toggle the state of the action between visible/invisible, enabled/disabled, and checked/not checked
changed()
, hovered()
, toggled()
, and triggered()
signals
The function QMainWindow::menuBar()
returns a pointer to the QMenuBar which is a child of the QMainWindow.
The menuBar()
function creates and returns a pointer to an empty QMenuBar child if the menu bar does not already exist.
Example 10.2. src/widgets/dialogs/messagebox/dialogs.cpp
[ . . . . ] /* Insert a menu into the menubar. */ QMenu* menu = new QMenu(tr("&Questions"), this); QMainWindow::menuBar()->addMenu(menu); /* Add some choices to the menu. */ menu->addAction(tr("&Ask question"), this, SLOT(askQuestion()), tr("Alt+A")); menu->addAction(tr("Ask a &dumb question"), this, SLOT(askDumbQuestion()), tr("Alt+D")); }
Generated: 2012-03-02 | © 2012 Alan Ezust and Paul Ezust. |