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. [Solved] Forward key event
Forum Updated to NodeBB v4.3 + New Features

[Solved] Forward key event

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 2 Posters 2.5k Views 1 Watching
  • 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.
  • E Offline
    E Offline
    ephe
    wrote on last edited by
    #1

    I've got a Rectangle and a TextInput.
    The focus is on the Recangle, and when I press any character, I want the focus to be on the TextInput and also the character should be written into the TextInput element.

    In the Rectangle I've got
    @
    Keys.onPressed:
    {
    textinput.forceActiveFocus();
    textinput.Keys.pressed(event);
    }
    @

    but this doesn't work.

    @
    Keys.forwardTo: [textinput]
    @

    is not working either.

    I don't know how I can forward the keys to the TextInput element.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      raaghuu
      wrote on last edited by
      #2

      See if this works(not 100% sure) :
      @
      Keys.onPressed:
      {
      textinput.forceActiveFocus()
      textinput.text = event.text
      }
      @

      1 Reply Last reply
      0
      • E Offline
        E Offline
        ephe
        wrote on last edited by
        #3

        Sadly, this is replacing the whole text of the TextInput

        1 Reply Last reply
        0
        • R Offline
          R Offline
          raaghuu
          wrote on last edited by
          #4

          @
          Keys.onPressed:
          {
          textinput.forceActiveFocus()
          prevText = textInput.text
          textinput.text = prevText + event.text
          }
          @

          1 Reply Last reply
          0
          • E Offline
            E Offline
            ephe
            wrote on last edited by
            #5

            This is working in general. My problem is though that I'm using a validator and an input mask. Also my textinput.text property is bound to a C++ property.

            The binding is not working anymore afterwards. I could do validating and everything by hand, but I hoped that there would be an easier solution.

            1 Reply Last reply
            0
            • R Offline
              R Offline
              raaghuu
              wrote on last edited by
              #6

              well, you could connect textInput.text to a custom curText property using onTextChanged and then bind that to the C++...

              P.S. - I don't get how validator and input mask are a problem

              1 Reply Last reply
              0

              • Login

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