From d85794c231dba314889cc2941014c422d22871db Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Thu, 6 May 2021 17:07:41 +0200 Subject: [PATCH] Respect Password and NoEcho mode while pre-editing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit During composition of text using an input method, incomplete characters should not be visible at all in NoEcho mode, and should be replaced by the password character in Password mode. In NoEcho mode, when the cursor is always at position 0, the pre-edit cursor should also always be at that position so that the UI doesn't give away the length of the text entered so far. Task-number: QTBUG-84664 Change-Id: I44a30eee3f5c6fe9fa00073b0a8ac3c333fbaa59 Reviewed-by: Tor Arne Vestbø Reviewed-by: Lars Knoll --- src/widgets/widgets/qwidgetlinecontrol.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/widgets/widgets/qwidgetlinecontrol.cpp b/src/widgets/widgets/qwidgetlinecontrol.cpp index 77c62b106b9..35541b455c5 100644 --- a/src/widgets/widgets/qwidgetlinecontrol.cpp +++ b/src/widgets/widgets/qwidgetlinecontrol.cpp @@ -573,7 +573,21 @@ void QWidgetLineControl::processInputMethodEvent(QInputMethodEvent *event) } } #ifndef QT_NO_IM - setPreeditArea(m_cursor, event->preeditString()); + // in NoEcho mode, the cursor is always at the beginning of the lineedit + switch (m_echoMode) { + case QLineEdit::NoEcho: + setPreeditArea(0, QString()); + break; + case QLineEdit::Password: { + QString preeditString = event->preeditString(); + preeditString.fill(m_passwordCharacter); + setPreeditArea(m_cursor, preeditString); + break; + } + default: + setPreeditArea(m_cursor, event->preeditString()); + break; + } #endif //QT_NO_IM const int oldPreeditCursor = m_preeditCursor; m_preeditCursor = event->preeditString().length();