From 0ef190fcc429405200d9f6063851726fcfb75637 Mon Sep 17 00:00:00 2001 From: Tianlu Shao Date: Mon, 9 Aug 2021 20:38:04 +0800 Subject: [PATCH] QCompleter: QCompleter unexpectedly changes QLineEdit text When qcompleter and qlineedit are used together, the currentcompletion() of qcompleter is its first item by default. Therefore, when qlineedit makes the initial value, then selects the text and enters, qcompleter will modify the default first item to qlineedit text. The judgment that completionprefix() of the completer is not empty is modified and added here, because completionprefix() is always empty when there is no match. Fixes: QTBUG-20894 Pick-to: 6.2 6.1 5.15 Change-Id: Id47f7f4da0a93d03a4e7b056ec731615b0803d13 Reviewed-by: Richard Moe Gustavsen Reviewed-by: Tianlu Shao --- src/widgets/widgets/qwidgetlinecontrol.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/widgets/widgets/qwidgetlinecontrol.cpp b/src/widgets/widgets/qwidgetlinecontrol.cpp index 65fd23aabb..b094c114a8 100644 --- a/src/widgets/widgets/qwidgetlinecontrol.cpp +++ b/src/widgets/widgets/qwidgetlinecontrol.cpp @@ -1672,6 +1672,7 @@ void QWidgetLineControl::processKeyEvent(QKeyEvent* event) break; #endif if (!m_completer->currentCompletion().isEmpty() && hasSelectedText() + && !m_completer->completionPrefix().isEmpty() && textAfterSelection().isEmpty()) { setText(m_completer->currentCompletion()); inlineCompletionAccepted = true;