PDA

View Full Version : Shortcut for QMenu



Ryhel
14th March 2007, 14:15
Hello! If anybody could help me with creating keyboard shortcut for QMenu item in a QMenuBar of QMainWindow? I need to open the QMenu items by pressing functional buttons (F1, F2, etc.) and QMenu::menuAction()->setShortcut(QKeySequence("F1")) have no effect. Qt-x11-opensource-4.2.3.

aamer4yu
15th March 2007, 06:22
I am also not getting the action by pressing F1 or other keys...

However we can use combination of Alt + keys for displaying the menu.

eg: menu = menuBar()->addMenu(tr("&File"));

This will pop the File menu on pressing Alt + F

Hope this helps :)

Lykurg
15th March 2007, 09:11
Hi, a solution could be:

void myBaseClass::keyPressEvent( QKeyEvent *e )
{
switch ( e->key() )
{
case Qt::Key_F1:
myF1Action->trigger();
break;
}
e->accept();
}


Lykurg

Ryhel
15th March 2007, 12:57
Thank you, this can be a solution. However shortcuts (including F-keys), that are set to QAction items of a QMenu work fine, so that actions are triggered, but if I want QMenu to open when pressing keys without Alt and call QMenu::menuAction()->setShortcut() - this unfortunately doesn`t work.