[Solved] Forward key event



  • 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.



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



  • Sadly, this is replacing the whole text of the TextInput



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



  • 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.



  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.