Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved How do I end activeFocus?

    General and Desktop
    1
    1
    59
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      Circuits last edited by

      I have a TextInput and I am looking for a way to end activeFocus s/t once a user presses enter on the Qt virtualKeyboard activeFocus falls off of the TextInput. I am trying to use the selectAll() method and this is working but not the way I need it to work, here is my code:

      TextInput{
                  id:inputItem
                  text: "Enter text here"
      
                  EnterKeyAction.enabled: inputItem.text.length > 0 || inputItem.inputMethodComposing
                  EnterKeyAction.label: "Next"
      
                  Keys.onReleased: {
                      if (event.key === Qt.Key_Return) {
                          activeFocus = false
                      }
                  }
      
                  onActiveFocusChanged: {
                      if(activeFocus) {
                          selectAll()
                          inputPanelContainer.textDisplay = inputItem.text
                      }
                  }
      
                  onDisplayTextChanged: {
                      inputPanelContainer.textDisplay = text
                  }
              }
          }
      

      So, currently, the first time I click in the TextInput box the string is highlighted; however, the cursor just stays in the TextInput box even after I press enter. I want the focus to fall off of the TextInput each time the user enters their string s/t when they click the TextInput box again the string will highlight again, is this possible? Perhaps I am calling selectAll() in the wrong way or perhaps I am setting activeFocus incorrectly?

      1 Reply Last reply Reply Quote 0
      • First post
        Last post