PDA

View Full Version : Button shortcut call an element in the menu



mourad
28th May 2008, 10:50
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

lyuts
28th May 2008, 11:30
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.

merry
28th May 2008, 12:41
In Mac O.S set short cut like this:

btRechRap->setShortcut(tr("CTRL+R"));

mourad
28th May 2008, 16:59
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

jpn
28th May 2008, 20:56
Mnemonics (http://doc.trolltech.com/latest/qkeysequence.html#mnemonic) override shortcuts, don't they? Most likely you have a menu item with name including "&I".

mourad
29th May 2008, 10:02
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.