geek
geek

Reputation: 816

Clearing textinput in QML

I have textInput box:

TextInput {           
    x: 5
    y: 2
    maximumLength: 16
    width: maximumLength * 20
    height: 17
    focus: false
    validator: RegExpValidator { regExp: /\d+/ }
    KeyNavigation.down: amount
}

And a clear button. When I click on clear button it should clear the text input box. How to do it?

Upvotes: 2

Views: 6716

Answers (3)

Tihran
Tihran

Reputation: 181

There is a clear() method in TextInput: https://doc.qt.io/qt-5/qml-qtquick-textinput.html#clear-method

Upvotes: 0

Nilesh Suryawanshi
Nilesh Suryawanshi

Reputation: 119

Try this one with your MouseArea:

onClicked: {
  textEdit1.text = " "
  mouseArea4.visible = false
}

Upvotes: 1

Kirween
Kirween

Reputation: 1538

You have to add the id property to your TextInput element.

TextInput {
    id: mytextbox
    x: 5
    y: 2
    ...
}

And on the event click of your MouseArea for your clear button you can do:

    onClicked: {
        mytextbox.text = "0"; 
    }

Upvotes: 3

Related Questions