I have dialog with space and return references. I want to also be able to catch the physical keystrokes on my keyboard. everything appears to be work except for.
key_return, key_space, key_tab, key_enter. I am focusing on key_Return not the numpad key_enter.
the following will not trigger any event for any of the above keys.
.h
protected
.h
protected
void keyPressEvent(QKeyEvent *);
To copy to clipboard, switch view to plain text mode
.cpp
void KeyBoard
::keyPressEvent(QKeyEvent *event
) {
qDebug()<<"event";
}
.cpp
void KeyBoard::keyPressEvent(QKeyEvent *event)
{
qDebug()<<"event";
}
To copy to clipboard, switch view to plain text mode
I have also tried the following with no event trigger. all other in keystrokes are working fine.
.h
protected
.h
protected
bool eventFilter(QObject *obj, QEvent *event);
To copy to clipboard, switch view to plain text mode
.cpp
{
qDebug()<<"event";
if(event
->type
() == QEvent::KeyPress) { QKeyEvent *key
= static_cast<QKeyEvent
*>
(event
);
qDebug() << "key " << key->key() << "from" << obj;
}
return QObject::eventFilter(obj, event
);
}
.cpp
bool KeyBoard::eventFilter(QObject* obj, QEvent* event)
{
qDebug()<<"event";
if(event->type() == QEvent::KeyPress) {
QKeyEvent *key = static_cast<QKeyEvent *>(event);
qDebug() << "key " << key->key() << "from" << obj;
}
return QObject::eventFilter(obj, event);
}
To copy to clipboard, switch view to plain text mode
I have been struggling with this for a couple days now.
Bookmarks