title: C++ Qt QShortcut with numpad key
body: <p><a href="http://qt-project.org/doc/qt-4.8/qshortcut.html" rel="nofollow noreferrer">QShortcut</a> makes it easy to connect a QShortcutEvent (Key press, combination or sequence) to a slot method, e.g.:</p>
  
  <pre><code>QShortcut *shortcut = new QShortcut( QKeySequence(Qt::Key_7), this, 0, 0, Qt::ApplicationShortcut);
  </code></pre>
  
  <p>(Hint: for number keys, a QSignalMapper can be used to map the QShortcut's <code>activated()</code> signal to a Slot with <code>int</code> parameter).</p>
  
  <p>However, in this example, with NumLock (<a href="https://en.wikipedia.org/wiki/Numeric_keypad" rel="nofollow noreferrer">numpad</a> enabled), both '7' keys will trigger the Shortcut's <code>activated()</code> signal.</p>
  
  <p>Is there a way to detect the different keys other than filtering or reimplementing a widget's <a href="http://qt-project.org/doc/qt-4.8/qwidget.html#keyPressEvent" rel="nofollow noreferrer">keyPressEvent</a> and check <a href="http://qt-project.org/doc/qt-4.8/qkeyevent.html#modifiers" rel="nofollow noreferrer">QKeyEvent::modifiers()</a> for <a href="http://qt-project.org/doc/qt-4.8/qt.html#KeyboardModifier-enum" rel="nofollow noreferrer">Qt::KeypadModifier</a>?</p>
  
  <p>Digging further, I found</p>
  
  <p><a href="http://bugreports.qt.io/browse/QTBUG-20191" rel="nofollow noreferrer">QTBUG-20191 Qt::KeypadModifier does not work with setShortcut</a> linking to a <a href="https://codereview.qt-project.org/#/c/15188/2/src/gui/kernel/qshortcutmap.cpp" rel="nofollow noreferrer">patch that has been merged into 4.8 in Sept. 2012</a> and which comes with a <a href="https://codereview.qt-project.org/#/c/15188/2/tests/auto/qpushbutton/tst_qpushbutton.cpp" rel="nofollow noreferrer">test case</a> using </p>
  
  <pre><code>button2-&gt;setShortcut(Qt::Key_5 + Qt::KeypadModifier);
  </code></pre>
  
  <p>which does not work for my QShortcut on Qt 4.8.1, i.e. neither of the '7' keys are recognized using (adding) the modifier flag.</p>
  
  <p>So I guess the quickest way would be installing a filter to detect the modifier and let all other keyEvents be handled by the default implementation to be useable with QShortcut?</p>