hi
i want to catch a combination of keypresses inside keyPressEvent such as shift+K;
normally single key presses can be caught inside keyPressEvent using case statements .
how to catch combination of keypresses inside keyPressEvent.
hi
i want to catch a combination of keypresses inside keyPressEvent such as shift+K;
normally single key presses can be caught inside keyPressEvent using case statements .
how to catch combination of keypresses inside keyPressEvent.
See QKeyEvent docs.
Hint: Shift is so called modifier.
J-P Nurmi
i tried like the below and it did not worked. how to use the modifier inside keypressevent.
Qt Code:
switch (event->key()) { case (Qt::Key_1): if (event->modifiers()==Qt::ShiftModifier) qDebug()<<"shift and one"; break; } }To copy to clipboard, switch view to plain text mode
That's the way keyboards work. When you press Shift+1, at least on western keyboards it produces an exclamation mark ("!"), not one ("1") right? There is Qt::Key_Exclam for that. You might be able to get Shift+1 when you use numpad.
J-P Nurmi
i want to enter in to a case(switch-case) when shift and one (Shift+1) is pressed .how do i do it inside keyPressEvent.
As I said, you can do it with the numpad only. And you will have to change the if-statement because Qt::KeypadModifier will be active as well:
Qt Code:
if (event->modifiers() & Qt::ShiftModifier) ...To copy to clipboard, switch view to plain text mode
J-P Nurmi
babu198649 (13th May 2008), spagatoni (14th July 2009)
thanks jpn it works,
is there any advantage in using bitwise AND operator in preference to == operator(although both works). How does the bitwise AND operator works here(ie. logic ) .
Bookmarks