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);
m_clearBlockAction = new QAction(tr("Clear selection"), this);
m_clearBlockAction->setShortcut(tr("Esc"));
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:
bool WidgetCtrl
::event(QEvent *e
) {
if (e
->type
() == QEvent::KeyPress) {
QKeyEvent *keyEvent
= static_cast<QKeyEvent
*>
(e
);
if (keyEvent->key() == Qt::Key_Escape)
{
qDebug() <<"ESC";
}
}
}
bool WidgetCtrl::event(QEvent *e)
{
if (e->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(e);
if (keyEvent->key() == Qt::Key_Escape)
{
qDebug() <<"ESC";
}
}
}
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
Bookmarks