summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/widgets/widgets/qcombobox.cpp5
-rw-r--r--tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp39
2 files changed, 43 insertions, 1 deletions
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp
index 40cf2f0f95..3555c5f261 100644
--- a/src/widgets/widgets/qcombobox.cpp
+++ b/src/widgets/widgets/qcombobox.cpp
@@ -2074,8 +2074,11 @@ void QComboBoxPrivate::setCurrentIndex(const QModelIndex &mi)
currentIndex = QPersistentModelIndex(normalized);
if (lineEdit) {
const QString newText = itemText(normalized);
- if (lineEdit->text() != newText)
+ if (lineEdit->text() != newText) {
lineEdit->setText(newText);
+ if (lineEdit->completer())
+ lineEdit->completer()->setCompletionPrefix(newText);
+ }
updateLineEditGeometry();
}
if (indexChanged) {
diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
index 23d0ffd2d2..4e0808a7b3 100644
--- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
+++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
@@ -158,6 +158,7 @@ private slots:
void highlightedSignal();
void itemData();
void task_QTBUG_31146_popupCompletion();
+ void task_QTBUG_41288_completerChangesCurrentIndex();
void keyboardSelection();
void setCustomModelAndView();
void updateDelegateOnEditableChange();
@@ -3026,6 +3027,44 @@ void tst_QComboBox::task_QTBUG_31146_popupCompletion()
QCOMPARE(comboBox.currentIndex(), 0);
}
+void tst_QComboBox::task_QTBUG_41288_completerChangesCurrentIndex()
+{
+ QComboBox comboBox;
+ comboBox.setEditable(true);
+
+ comboBox.addItems(QStringList() << QStringLiteral("111") << QStringLiteral("222"));
+
+ comboBox.show();
+ comboBox.activateWindow();
+ QVERIFY(QTest::qWaitForWindowActive(&comboBox));
+
+ {
+ // change currentIndex() by keyboard
+ comboBox.lineEdit()->selectAll();
+ QTest::keyClicks(comboBox.lineEdit(), "222");
+ QTest::keyClick(comboBox.lineEdit(), Qt::Key_Enter);
+ QCOMPARE(comboBox.currentIndex(), 1);
+
+ QTest::keyClick(&comboBox, Qt::Key_Up);
+ comboBox.lineEdit()->selectAll();
+ QTest::keyClick(comboBox.lineEdit(), Qt::Key_Enter);
+ QCOMPARE(comboBox.currentIndex(), 0);
+ }
+
+ {
+ // change currentIndex() programmatically
+ comboBox.lineEdit()->selectAll();
+ QTest::keyClicks(comboBox.lineEdit(), "222");
+ QTest::keyClick(comboBox.lineEdit(), Qt::Key_Enter);
+ QCOMPARE(comboBox.currentIndex(), 1);
+
+ comboBox.setCurrentIndex(0);
+ comboBox.lineEdit()->selectAll();
+ QTest::keyClick(comboBox.lineEdit(), Qt::Key_Enter);
+ QCOMPARE(comboBox.currentIndex(), 0);
+ }
+}
+
void tst_QComboBox::keyboardSelection()
{
QComboBox comboBox;