QMenu* menu
= menuBar
()->addMenu
("Menu");
QAction* action
= menu
->addAction
("Action");
connect(action, SIGNAL(triggered()), this, SLOT(act()));
// alternative shortcuts
QAction* del
= menu
->addAction
("");
del->setVisible(false);
QAction* bak
= menu
->addAction
("");
bak->setVisible(false);
connect(del, SIGNAL(triggered()), action, SLOT(trigger()));
connect(bak, SIGNAL(triggered()), action, SLOT(trigger()));
// By the way
// QAction* del = new QAction("", this);
// didn't work even if I set the shortcut context to Qt::ApplicationShortcut.
// At least I couldn't get the actions triggered until I added them in the menu.
// So that's why I added the alternative actions in the menu as hidden..
QMenu* menu = menuBar()->addMenu("Menu");
QAction* action = menu->addAction("Action");
action->setShortcut(QKeySequence("Del, Backspace"));
connect(action, SIGNAL(triggered()), this, SLOT(act()));
// alternative shortcuts
QAction* del = menu->addAction("");
del->setShortcut(QKeySequence("Del"));
del->setVisible(false);
QAction* bak = menu->addAction("");
bak->setShortcut(QKeySequence("Backspace"));
bak->setVisible(false);
connect(del, SIGNAL(triggered()), action, SLOT(trigger()));
connect(bak, SIGNAL(triggered()), action, SLOT(trigger()));
// By the way
// QAction* del = new QAction("", this);
// didn't work even if I set the shortcut context to Qt::ApplicationShortcut.
// At least I couldn't get the actions triggered until I added them in the menu.
// So that's why I added the alternative actions in the menu as hidden..
To copy to clipboard, switch view to plain text mode
Bookmarks