10.1.  QActions, QMenus, and QMenuBars

[ fromfile: menus.xml id: menus ]

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"));
}



[48] A context menu is usually activated by clicking the right mouse button or by pressing the menu button. It is called a context menu because the menu always depends on the context (which QWidget or item is currently selected or focused).