Qt/QML for Android - virtual keyboard key event handling



  • Hi Everybody!
    I've just joined in the Forum. I'm a beginner in Qt. I've faced a problem on QML. I'm making an app for Android. Created a TextInput object and when I press on it, it automatically sets a focus and the system-virtual keyboard appears. I handled some key events by Keys object, i.e: onReturnPressed, onBackPressed... So, I also need to handle the 'Plus' key, but onPressed event can't recognize it. Is there any solution for it? Here's my code:

    TextInput {

            property string placeholderText: "Input summ"
    
            id: txtin
            color: "black"
            anchors {
                top: summInfo.bottom
                topMargin: 20
                horizontalCenter: parent.horizontalCenter
            }
            width: parent.width-200
            height: 80
            text: ""
            font.pixelSize: 45
            horizontalAlignment: TextInput.AlignHCenter
            verticalAlignment: TextInput.AlignVCenter
            inputMethodHints: "ImhPreferNumbers"
            maximumLength: 9
            validator: DoubleValidator{
                notation: DoubleValidator.StandardNotation
                bottom: 0
                decimals: 2
            }
    
            Keys.onBackPressed: {
                centerFrame.focus = true
            }
    
            Keys.onPressed: {
                //if (event.key == Qt.Key_Plus) // HERE IS THE PROBLEM
                    console.log(event.key)
            }
    

    }


  • Moderators

    @davronito said in Qt/QML for Android - virtual keyboard key event handling:

    So, I also need to handle the 'Plus' key, but onPressed event can't recognize it.

    you mean that Keys.onPressed is not triggered at all for the plus key?



  • @raven-worx yes, exactly. And I also tried Keys.onNumberSignPressed, but no effect yet


Log in to reply