如果我希望有一个QMenu,显示字串是“文件”,快捷键是“Ctrl+F”.
使用代码能实现这样一个菜单么?该怎么作?
------解决方案--------------------
QAction *act = new QAction(QString::fromLocal8Bit("文件"));
act->setShortcut(tr("Ctrl+F"));
------解决方案--------------------
menu一般用 Alt+XXX
new QMenu("&File", this);
非要用Ctrl+F就在keyPressedEvent里抓吧。。
------解决方案--------------------
menu->addAction(...);
void QMenu::addAction ( QAction * action )
Appends the action action to the menu's list of actions.
void QMenuBar::addAction ( QAction * action )
Appends the action action to the menu bar's list of actions.
------解决方案--------------------
//class define/////////////
QMenu *fileMenu;
QAction *newAction;
///////////////////////////
//void createAction();////
newAction = new QAction(tr("&New"), this);
newAction->setShortCut(tr("Ctrl+F"));
//or (newAction->setShortCut(QKeySequence::New));)
//////////////////////////
//void createMenu();//////
fileMenu = MenuBar()->addMenu(tr("File"));
fileMenu->addAction(newAction)
//////////////////////////