Results 1 to 4 of 4

Thread: Shortcut for QMenu

  1. #1
    Join Date
    Mar 2007
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Shortcut for QMenu

    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.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Shortcut for QMenu

    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

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Shortcut for QMenu

    Hi, a solution could be:
    Qt Code:
    1. void myBaseClass::keyPressEvent( QKeyEvent *e )
    2. {
    3. switch ( e->key() )
    4. {
    5. case Qt::Key_F1:
    6. myF1Action->trigger();
    7. break;
    8. }
    9. e->accept();
    10. }
    To copy to clipboard, switch view to plain text mode 

    Lykurg

  4. #4
    Join Date
    Mar 2007
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Shortcut for QMenu

    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.

Similar Threads

  1. Strange shortcut problem
    By blukske in forum Qt Programming
    Replies: 0
    Last Post: 13th March 2007, 10:26
  2. Qt 4.2 Shortcut Management
    By dvmorris in forum Qt Programming
    Replies: 20
    Last Post: 5th March 2007, 20:48
  3. shortcut with more than one key
    By ChasW in forum Qt Programming
    Replies: 1
    Last Post: 26th January 2007, 06:38
  4. Trying to set shortcut
    By mikro in forum Newbie
    Replies: 2
    Last Post: 30th November 2006, 09:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.