View Full Version : Shortcut: CTRL + SHIFT + "letters"

18th May 2009, 19:07
im having a problem with 3 key shortcut. I'm trying to add to an action this:

action->->setShortcut(QKeySequence( (Qt::CTRL+Qt::SHIFT), Qt::Key_1)) but isn't trigeer, does anyone have an idea how to implement a 3 Key Shortcut??


18th May 2009, 20:01
Shouldn't it be:


18th May 2009, 20:07
OH YEAH, im sorry, wrong code :P but QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_1) also didn't work and QKeySequence(Qt::CTRL,Qt::SHIFT,Qt::Key_1). My concern is if it is able to do it... or somebody have same problems. I have also 2 keys shortcuts in the same class and there are fine.

18th May 2009, 20:55


18th May 2009, 21:51
nothing... I changed it to
QKeySequence(tr("Ctrl+Shift+1")) but nothing has trigger. Put on it a breakpoint to verify that isn't triggering.

18th May 2009, 22:09
So obviously the reason is not here. Can we see a larger snippet of code? How do you create and use the action?

18th May 2009, 22:12
void QtContactMenu::createSortMenu( QObject* parent )

createAction( &_actionSortAlpha, pMenu, tr("Alphabetically"), true, QtEnumSortOption::SortAlpha, "", QKeySequence(tr("Ctrl+Shift+1")) );
createAction( &_actionSortPresence, pMenu, tr("Presence"), true, QtEnumSortOption::SortPresence, "", QKeySequence(tr("Ctrl+Shift+2")) );
createAction( &_actionSortRandom, pMenu, tr("Random"), true, QtEnumSortOption::SortRandom, "", QKeySequence(tr("Ctrl+Shift+3")) );


void QtContactMenu2::createAction( QAction** ppAction, QMenu* pMenu, const QString& text, bool bCheckable, int data, const char* iconPath, QKeySequence & shortcut ){
*ppAction = new QAction( text, NULL ); //, parent );

(*ppAction)->setCheckable( bCheckable );
(*ppAction)->setData(qVariantFromValue(data) );

if ( iconPath && (strlen( iconPath ) > 0 ) )
QIcon icon1;
icon1.addPixmap(QPixmap( QString::fromUtf8(iconPath)), QIcon::Normal, QIcon::Off);
if (shortcut){
pMenu->addAction( *ppAction );


18th May 2009, 22:40
First of all please provide a parent for the action.
What is pMenu (I mean the base class of it)? Is it visible anywhere on the screen?

18th May 2009, 22:46
pMenu is a QMenu object, thats the menu on the app.

What difference makes the parent?? I'm asking because if you set this:

createAction( &_actionSortAlpha, pMenu, tr("Alphabetically"), true, QtEnumSortOption::SortAlpha, "", QKeySequence(tr("Ctrl+1")) );

this shortcut works without any problem...

18th May 2009, 23:26
This works for me just fine:

#include <QtGui>

int main(int argc, char **argv){
QApplication app(argc, argv);
QToolButton pb;
QAction *act = new QAction(&app);
QObject::connect(act, SIGNAL(triggered()), &app, SLOT(quit()));
return app.exec();

The only reason I can think of is that the menu is not the active widget and thus the action is inactive. But then the second snippet you posted shouldn't have worked as well.

19th May 2009, 00:00
thats the wear part, 2 keys works but 3 dont.

19th May 2009, 00:13
Could you test if my example works for you?

21st May 2009, 23:36
Hey Wisota, is working but only with keyboard numbers, the numbers on the numpad of the keyboard dont react on it, I do it just once but no more.... Are keyboard nums and numpad nums different for QT??

21st May 2009, 23:57
Do you have NumLock enabled on your keyboard?

22nd May 2009, 00:12
Yeap :p With or Without the NumLock, Keyboard nums works but NumPad don't

22nd May 2009, 01:00
Yeap :p With or Without the NumLock, Keyboard nums works but NumPad don't

It works for me just fine when using the numeric key pad with NumLock active. Or at least with a pseudo-keypad (I have a laptop without a real keypad, only one made of special function keys).

22nd May 2009, 01:44
Maybe.... im not pressing CRTL + SHIFT + 1 but I'm pressing CTL + ! (which is SHIFT + 1)> That why sometimes works

22nd May 2009, 10:34
I don't know what you are pressing :) "!" is "!", "Shift+1" is "Shift+1". You can have different keyboard layouts and some of them won't have "!" as "Shift+1". It works for me when I press Ctrl, Shift and 1.