Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Howto hide blinking cursor from InActive TextInput

Howto hide blinking cursor from InActive TextInput

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 535 Views
  • 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.
  • P Offline
    P Offline
    pingal
    wrote on 28 Jan 2022, 07:39 last edited by pingal
    #1

    I've a TextInput like below:

    TextInput {
                id: num_id
                text: "1234"
                font.pixelSize: 20
                selectByMouse: true
                anchors.fill: parent
                validator: IntValidator {bottom: 1; top: 100000} 
            }
    

    Everytime i enter something, cursor appears as expected. But I want to hide the cursor when i click outside TextInput.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lemons
      wrote on 28 Jan 2022, 12:01 last edited by
      #2

      You can simply catch all unhandled click events below your inputs.
      Please note if you apply anchors.fill to the TextInput and the TapHandler has the same clickable area, all click events will stay in the TextInput as it covers the entire area of the TapHandler.
      Compare to the example below with the Rectangle indicating the area of the TextInput.

      Item{
          id: contentWrapper
          anchors.fill: parent
      
          TapHandler{
              id: clickOutsideCatcher
              onTapped: {
                  console.debug("catched click outside")
                  // this removes the active focus from the input field
                  contentWrapper.forceActiveFocus()
              }
          }
          
          Rectangle{
              id: highlightTextInputArea
              anchors.fill: num_id
              color: "red"
          }
      
          TextInput {
              id: num_id
              text: "1234"
              font.pixelSize: 20
              selectByMouse: true
              //anchors.fill: parent
              validator: IntValidator {bottom: 1; top: 100000}
          }
      }
      
      1 Reply Last reply
      0

      1/2

      28 Jan 2022, 07:39

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved