QShortcut makes it easy to connect a QShortcutEvent (keystroke, combination, or sequence) to a slot method, for example:
QShortcut *shortcut = new QShortcut( QKeySequence(Qt::Key_7), this, 0, 0, Qt::ApplicationShortcut);
(Hint: for numeric keys, QSignalMapper can be used to map the activated() signal of QShortcut activated() to the slot with the int parameter).
However, in this example, with NumLock ( numpad enabled), both keys "7" will trigger the activated() signal of the activated() shortcut.
Is there a way to detect other keys besides filtering or overriding the keyPressEvent widget and checking QKeyEvent :: modifiers () for Qt :: KeypadModifier ?
Digging further, I found
QTBUG-20191 Qt :: KeypadModifier does not work with setShortcut link to a patch that was merged into 4.8 in September 2012 and that comes with a test case using
button2->setShortcut(Qt::Key_5 + Qt::KeypadModifier);
which does not work for my QShortcut on Qt 4.8.1, that is, none of the '7' keys is recognized by (adding) a modifier flag.
So I think the fastest way would be to set a filter to detect the modifier and let all other keyEvents be handled by the default implementation for use with QShortcut?
source share