From 9b15f7909baa99714569efce6abcde67212b50a2 Mon Sep 17 00:00:00 2001 From: Tom Dewey Date: Fri, 15 Dec 2023 13:15:19 +0000 Subject: [PATCH] qml: Clear saved password using onPressed handler Using onTextEdited meant that the clear() call would happen after the edit had actually happened. Instead, use the Keys.onPressed handler, which happens earlier in the input chain. --- src/OptionsPopup.qml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/OptionsPopup.qml b/src/OptionsPopup.qml index 8fe7413..94be42c 100644 --- a/src/OptionsPopup.qml +++ b/src/OptionsPopup.qml @@ -153,19 +153,26 @@ Window { } TextField { id: fieldUserPassword - echoMode: TextInput.Password + echoMode: TextInput.PasswordEchoOnEdit Layout.minimumWidth: 200 selectByMouse: true property bool alreadyCrypted: false property bool indicateError: false - onTextEdited: { + Keys.onPressed: (event)=> { if (alreadyCrypted) { /* User is trying to edit saved (crypted) password, clear field */ alreadyCrypted = false clear() } + + // Do not mark the event as accepted, so that it may + // propagate down to the underlying TextField. + event.accepted = false + } + + onTextEdited: { if (indicateError) { indicateError = false }