serget
21st January 2012, 15:04
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:
m_clearBlockAction = new QAction(tr("Clear selection"), this);
m_clearBlockAction->setShortcut(tr("Esc"));
addAction(m_clearBlockAction);
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:
bool WidgetCtrl::event(QEvent *e)
{
if (e->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(e);
if (keyEvent->key() == Qt::Key_Escape)
{
qDebug() <<"ESC";
}
}
}
qDebug() <<"ESC" is never gets executed; once I remove shortcut from action, event code works.
Any help?
Thanks
Serge T
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:
m_clearBlockAction = new QAction(tr("Clear selection"), this);
m_clearBlockAction->setShortcut(tr("Esc"));
addAction(m_clearBlockAction);
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:
bool WidgetCtrl::event(QEvent *e)
{
if (e->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(e);
if (keyEvent->key() == Qt::Key_Escape)
{
qDebug() <<"ESC";
}
}
}
qDebug() <<"ESC" is never gets executed; once I remove shortcut from action, event code works.
Any help?
Thanks
Serge T