Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear TextField in QML on Android

I have a simple textfield:

TextField {
       id: searchField
       height: Units.dp * 40
       color: Palette.colors["white"]["500"]
       textColor: Palette.colors["white"]["500"]
       placeholderText: qsTr("Search...")

}

And I'm trying to clear TextField input as following:

function clearSearch() {
    Qt.inputMethod.reset()
    Qt.inputMethod.hide()
    searchField.focus = false
    searchField.text = ""
}

It seems that on Android function clearSearch doesn't work. What I see that text input still contains last entered text (I guess it is a displayText). Also I suppose that it is due autocomplete feature of the keyboard.

Am I clearing a text input the wrong way?

My test case:

  1. Enter something in the field, using virtual keyboard with autocomplete.
  2. Do not confirm input, leaving current word selected (underlined)
  3. Tap clear button (call to clearSearch())
  4. Notice that there is still an underlined text in a TextField
  5. Tap on a field again, and see that keyboard shows again, and text field is empty now

P.S. Qt 5.5

like image 405
Ivan Fateev Avatar asked Dec 22 '25 20:12

Ivan Fateev


1 Answers

You can call Qt.inputMethod.reset() to reset any partial uncommitted text input from an input method.

like image 114
jpnurmi Avatar answered Dec 24 '25 11:12

jpnurmi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!