Unfortunately, when you create UIs with QML this is not the default behavior. With some help from IRC #harmattan channel and some googling, this is how I got it to work:
TextField { Keys.onReturnPressed: { platformCloseSoftwareInputPanel() } }
Now the virtual keyboard is closed. But there is still one issue. The keyboard is closed, but the text input still retains focus. If you try clicking on the text field again to start typing, nothing happens. You will have to click somewhere else, so that it loses focus, and then click again the text field. The stock applications make the input field lose focus when the virtual keyboard is closed.
This was a little more hackish to implement. TextField contains a TextInput, which has focus property. But unfortunately TextField does not contain an alias for that property, so you can't just simply set focus = false for the TextField. This kind of rather ugly workaround does the job:
TextField { Keys.onReturnPressed: { platformCloseSoftwareInputPanel() dummy.focus = true } } // This is just a dummy invisible item that takes the focus when virtual keyboard is closed Item { id: dummy }
Hi,
ReplyDeleteCould you please write the implementation of platformCloseSoftwareInputPanel().
Thanks
platformCloseSoftwareInputPanel is included in the Harmattan components. So there is no need for you to implement it, it's callable inside TextField. The code should work as it is.
ReplyDelete