Results 1 to 6 of 6

Thread: Button shortcut call an element in the menu

  1. #1
    Join Date
    Mar 2008
    Posts
    55
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Button shortcut call an element in the menu

    Hello everyone, my Qt 4.3 application must run under Windows and Mac. But I've a problem with buttons shortcuts. When I put the "&" charactar before the shortcut letter, this does'nt work under Mac because the Alt is not supported on Mac. So I've added some code like :
    Qt Code:
    1. btRechRap->setShortcut(QKeySequence(tr("Alt+R")));
    2. btRechAp->setShortcut(QKeySequence(tr("Alt+D")));
    3. btEnlever->setShortcut(QKeySequence(tr("Alt+S")));
    4. btMono->setShortcut(QKeySequence(tr("Alt+M")));
    5. btInit->setShortcut(QKeySequence(tr("Alt+I")));
    6. btAnalyse->setShortcut(QKeySequence(tr("Alt+C")));
    To copy to clipboard, switch view to plain text mode 
    But under Windows, when I execute a combinaison like Alt+R, this cele activate an élément of the menu that I've attribute the same letter of shortcut
    Must I change the shortcuts of the menu. Can anyone help me and gives an other method to resolve this problem.
    Best Regards, Mourad
    Last edited by jpn; 28th May 2008 at 13:46. Reason: missing [code] tags

  2. #2
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Button shortcut call an element in the menu

    Quote Originally Posted by mourad View Post
    Hello everyone, my Qt 4.3 application must run under Windows and Mac. But I've a problem with buttons shortcuts. When I put the "&" charactar before the shortcut letter, this does'nt work under Mac because the Alt is not supported on Mac. So I've added some code like :
    btRechRap->setShortcut(QKeySequence(tr("Alt+R")));
    btRechAp->setShortcut(QKeySequence(tr("Alt+D")));
    btEnlever->setShortcut(QKeySequence(tr("Alt+S")));
    btMono->setShortcut(QKeySequence(tr("Alt+M")));
    btInit->setShortcut(QKeySequence(tr("Alt+I")));
    btAnalyse->setShortcut(QKeySequence(tr("Alt+C")));
    But under Windows, when I execute a combinaison like Alt+R, this cele activate an élément of the menu that I've attribute the same letter of shortcut
    Must I change the shortcuts of the menu. Can anyone help me and gives an other method to resolve this problem.
    Best Regards, Mourad
    Why won't you use such kind of call of QKeySequence(Qt::AltModifier + Qt::Key_R) ?

    I didn't have too much experience with Mac, but ... isn't it a META key instead of Alt?

    Looks like you need to check the OS the app is running on and depending on that use either Qt::AltModifier or Qt::MetaModifier.

  3. #3
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Button shortcut call an element in the menu

    In Mac O.S set short cut like this:
    btRechRap->setShortcut(tr("CTRL+R"));
    Always Believe in Urself
    Merry

  4. #4
    Join Date
    Mar 2008
    Posts
    55
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Button shortcut call an element in the menu

    Thanks for replying, but my problem now is on Windows. In the menu I've an element witch have CTRL+I as shortcut but in a dialog when I try to call a button with its ALT+I shortcut, always it is the element in the menu how is called.
    I dont understund how work the shortcuts in Qt.
    Can anyone telle how to do and resolve this problem

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Button shortcut call an element in the menu

    Mnemonics override shortcuts, don't they? Most likely you have a menu item with name including "&I".
    J-P Nurmi

  6. #6
    Join Date
    Mar 2008
    Posts
    55
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Button shortcut call an element in the menu

    I've tried without the source code adding the shortcuts. But always I've the same result. when I open a dialog and do ALT+I, this activate the element in the menu which have the CTRL+I shortcut !. Note that I've used QAction for the element in the menu. Is this can affect the function of shortcuts? If this is true, what I must to do?
    Best regards.

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.