Hi,

I'm implementing a context menu in QWidget derived class and I want an action to be triggered by Escape shortcut, so I set a shortcut when I create QAction:

Qt Code:
  1. m_clearBlockAction = new QAction(tr("Clear selection"), this);
  2. m_clearBlockAction->setShortcut(tr("Esc"));
  3. addAction(m_clearBlockAction);
To copy to clipboard, switch view to plain text mode 

The problem is shortcut does not work and even more - it intercepts (or does not allow to fire) key stroke events, i.e. even if I put direct handling into event filter, it does not catch Qt::Key_Escape code:

Qt Code:
  1. bool WidgetCtrl::event(QEvent *e)
  2. {
  3. if (e->type() == QEvent::KeyPress)
  4. {
  5. QKeyEvent *keyEvent = static_cast<QKeyEvent *>(e);
  6.  
  7. if (keyEvent->key() == Qt::Key_Escape)
  8. {
  9. qDebug() <<"ESC";
  10. }
  11. }
  12. }
To copy to clipboard, switch view to plain text mode 

qDebug() <<"ESC" is never gets executed; once I remove shortcut from action, event code works.


Any help?
Thanks
Serge T