Как вариант
C++ (Qt)
void MyWidget::focusOutEvent (QFocusEvent* event) {
QWidget::focusOutEvent(event);
...
...
}
void MyWidget::keyPressEvent (QKeyEvent* event) {
event->accept();
if(event->key()==Qt::Key_Return || event->key()==Qt::Key_Enter){
...
...
}
}