Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.4.0
-
None
Description
The documentation says: "editing finished: This signal is emitted when the Return or Enter key is pressed or the text field loses focus."
I would like to start an action when user presses ENTER. So, I'm using this signal. But if the window is moved or redimensionned (or others reasons), this signal is emitted too, because the focuse is lost.
Problem: focus and activeFocus are always being true in my slot. I had to use a timer to solve this case.
This code doesn't work, because activeFocus is always true:
ApplicationWindow { width: 640 height: 480 visible: true TextField{ onEditingFinished: { if( activeFocus ){ console.log("ENTER is pressed") //do... }else{ console.log("Focus is lost") } } } }
This code work:
ApplicationWindow { id: main title: qsTr("Trainenglish") width: 640 height: 480 visible: true TextField{ onEditingFinished: timer.start() Timer{ id: timer interval: 5 repeat: false running: false onTriggered: { if( parent.activeFocus ){ console.log("ENTER is pressed") //do... }else{ console.log("Focus is lost") } } } } }
ActiveFocus should be set to false before the emision of editingFinished, to be able to differentiate the cases.
Else, there should be two different signals. One for Entrer/Return and one for the focus lost (but onActiveFocusChanged already does that).