
Originally Posted by
skuda
when i press the enter in the doublespinbox, the okButton get the focus and automatically it is clicked.
Only "default" buttons react to return/enter and they disregard the focus in that matter.
Try this:
...
connect(testButton, SIGNAL(clicked()), SLOT(testButtonPressed()));
connect(spinBox, SIGNAL(editingFinished()), SLOT(testing()));
connect(emitButton, SIGNAL(clicked()), SLOT(messageLaunch()));
emitButton->installEventFilter( this );
emitButton->setAutoDefault( false );
emitButton->setDefault( false );
testButton->installEventFilter( this );
testButton->setAutoDefault( false );
testButton->setDefault( false );
}
{
if( b
!= 0 && e
->type
() == QEvent::KeyPress ) { if( ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return ) {
b->animateClick();
return true;
}
}
return false;
}
...
connect(testButton, SIGNAL(clicked()), SLOT(testButtonPressed()));
connect(spinBox, SIGNAL(editingFinished()), SLOT(testing()));
connect(emitButton, SIGNAL(clicked()), SLOT(messageLaunch()));
emitButton->installEventFilter( this );
emitButton->setAutoDefault( false );
emitButton->setDefault( false );
testButton->installEventFilter( this );
testButton->setAutoDefault( false );
testButton->setDefault( false );
}
bool TestDlg::eventFilter( QObject * o, QEvent * e )
{
QPushButton * b = qobject_cast< QPushButton * >( o );
if( b != 0 && e->type() == QEvent::KeyPress ) {
QKeyEvent * ke = static_cast< QKeyEvent * >( e );
if( ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return ) {
b->animateClick();
return true;
}
}
return false;
}
To copy to clipboard, switch view to plain text mode
Bookmarks