QComboBox and the QLineEdit inside both ignore key press events by default. This means that these events will be propagated to the parent widget, the dialog in your case.
One workaround is to subclass QComboBox and override keyPressEvent() to change the behaviour. You should get the returnPressed() signal in the normal way. The only difference is that the event won't be delivered to the dialog. The code could look more or less like this:
{
// let base class handle the event
if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return)
{
// accept enter/return events so they won't
// be ever propagated to the parent dialog..
e->accept();
}
}
void MyComboBox::keyPressEvent(QKeyEvent* e)
{
// let base class handle the event
QComboBox::keyPressEvent(e);
if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return)
{
// accept enter/return events so they won't
// be ever propagated to the parent dialog..
e->accept();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks