QComboBox lineEdit value not inserted in selection list
Solved
General and Desktop
-
The behaviour of an editable QComboBox allows the change of the selection list. However, the selction list is only changed when the new value has been typed and at the end the return/enter key is pressed.
When typing a vlaue and changing the focus with <tab>, or most likely also with others methods, the value remains in the line edit, but is not entered in the selection list.
This has a couple of disadvantages e.g. when application shall learn/extend the selection lists.
How can I convince QComboBox to add also entries to selection list as soon as the input widget is loosing focus?
-
Not directly. You have to fake it:
bool eventFilter(QObject* watched, QEvent* event) { if( watched == comboBox ) // or watched->inherits("QComboBox") ?? { // you may want to do additional checks here for a generic solution (like the combobox is really editable, it has a insert policy set, etc) switch( event->type() ) { case QEvent::FocusOut: { QKeyEvent keyEvent( QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier ); QCoreApplication::instance()->sendEvent( watched, &keyEvent ); } break; } } return BaseClass::eventFilter(watched,event); }