Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-46908

Textfield: editingFinished is emited before activeFocus update

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.4.0
    • Quick: Controls 1
    • 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).

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            vtitux Thierry Vetter
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes