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. Getting text from TextFiled before "OK" on keyboard is clicked
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 2 Posters 1.7k 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.
  • M Offline
    M Offline
    Marek
    wrote on last edited by
    #1

    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
            }
        }
    }
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      Marek
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

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

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        1
        • M Offline
          M Offline
          Marek
          wrote on last edited by
          #4

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

          "TextInput.onTextEdited" is not available in QtQuick 2.7.
          
          1 Reply Last reply
          0
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

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

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            1
            • M Offline
              M Offline
              Marek
              wrote on last edited by Marek
              #6

              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

              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