diff --git a/autotests/kcombobox_unittest.cpp b/autotests/kcombobox_unittest.cpp --- a/autotests/kcombobox_unittest.cpp +++ b/autotests/kcombobox_unittest.cpp @@ -132,6 +132,21 @@ delete testCombo; // not needed anymore } + void testLineEditCompletion() + { + // Test for KCombo's KLineEdit inheriting the completion object of the parent + KTestComboBox testCombo(false, nullptr); + QVERIFY(!testCombo.lineEdit()); + auto completion = testCombo.completionObject(); + QVERIFY(completion); + testCombo.setEditable(true); + auto lineEdit = qobject_cast(testCombo.lineEdit()); + QVERIFY(lineEdit); + QVERIFY(lineEdit->compObj()); + QCOMPARE(lineEdit->compObj(), completion); + QCOMPARE(testCombo.completionObject(), completion); + } + void testSelectionResetOnReturn() { // void QComboBoxPrivate::_q_returnPressed() calls lineEdit->deselect() diff --git a/src/kcombobox.cpp b/src/kcombobox.cpp --- a/src/kcombobox.cpp +++ b/src/kcombobox.cpp @@ -311,10 +311,17 @@ edit = kedit; } + // reuse an existing completion object, if it was configured already + auto completion = compObj(); + QComboBox::setLineEdit(edit); d->klineEdit = qobject_cast(edit); setDelegate(d->klineEdit); + if (completion && d->klineEdit) { + d->klineEdit->setCompletionObject(completion); + } + // Connect the returnPressed signal for both Q[K]LineEdits' if (edit) { connect(edit, SIGNAL(returnPressed()), SIGNAL(returnPressed()));