Getting text from TextFiled before "OK" on keyboard is clicked



  • Hi,

    I would like to have user entered text from TextField before users press "OK" on keyboard on the phone.
    Now I'm using onTextChanged but on the phone it is emitted when user press "OK" on keyboard, how to get text as the user enters it ?

    Best Regards
    Marek

    below id MyTextFiled.qml

    import QtQuick 2.9
    import QtQuick.Controls 2.2
    import QtQuick.Controls.impl 2.2
    import QtQuick.Templates 2.2 as T
    
    T.TextField {
        id: control
    
        implicitWidth: Math.max(background ? background.implicitWidth : 0,
                                placeholderText ? placeholder.implicitWidth + leftPadding + rightPadding : 0)
                                || contentWidth + leftPadding + rightPadding
        implicitHeight: Math.max(contentHeight + topPadding + bottomPadding,
                                 background ? background.implicitHeight : 0,
                                 placeholder.implicitHeight + topPadding + bottomPadding)
    
        padding: 6
        leftPadding: padding + 4
    
        opacity: enabled ? 1 : 0.2
        color: Default.textColor
        selectionColor: Default.textSelectionColor
        selectedTextColor: color
        verticalAlignment: TextInput.AlignVCenter
    
        PlaceholderText {
            id: placeholder
            x: control.leftPadding
            y: control.topPadding
            width: control.width - (control.leftPadding + control.rightPadding)
            height: control.height - (control.topPadding + control.bottomPadding)
    
            text: control.placeholderText
            font: control.font
            color: Default.textDisabledColor
            verticalAlignment: control.verticalAlignment
            visible: !control.length && !control.preeditText && (!control.activeFocus || control.horizontalAlignment !== Qt.AlignHCenter)
            elide: Text.ElideRight
        }
        background: Item {
            implicitHeight: 50
            BorderImage {
                source: "images/textinput.png"
                border.left: 8
                border.right: 8
                anchors.bottom: parent.bottom
                anchors.left: parent.left
                anchors.right: parent.right
            }
        }
    }
    


  • Really no one knows the answer?
    For instance in Google Map application when I'm typing place to go, below there are listed hints as I type, and in Qt when I type text it appears in TextFiled so somehow app must know this text.
    Maybe to use different type not TextField, tried TextInput but no difference.

    Marek



  • You can use TextInput instead of TextField, it has a textEdited signal



  • something strange, I have tried this earlier, when I compile app I got

    "TextInput.onTextEdited" is not available in QtQuick 2.7.
    


  • that's implemented from Qt5.9 onwards, you can use onTextChanged for earlier versions



  • I have Qt 5.9.1 so something must be messed up.
    I have set option

    inputMethodHints: Qt.ImhNoPredictiveText;
    

    and now signal onTextChanged is emitted from TextField as I type.
    But it is still different from other apps, because signal should be emitted event with predictiveText as in Google Maps app.

    ok I got it, need to import QtQuick 2.9 not 2.7


Log in to reply
 

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