Focusing TextInput doesn't open the virtual keyboard
-
Hi! I have a problem with windows keyboard not showing up when expected.
I am trying to create custom text input element based on TexInput. The input should get active focus when I press / tap on other areas of my custom element (like prefix or suffix), not only on the TextInput itself. And accordingly, I'd like the windows keyboard to appear when my app is displayed on the touchscreen.
When I run the example below: I tap in the top rectangle in the column, the keyboard doesn't popup. The same for the second rectangle: independent on where I tap - suffix, TextInput, or prefix - the keyboard doesn't pop up.
The order in which I tap those Rectangles doesn't matter - the keyboard doesn't appear.Now, If in both my Rectangles I use TextField instead of TextInput: I tap on the first rectangle: keyboard appears (not on the same screen as the application, but at least it pops up). I close the app, open it again and tap on second Rectangle's prefix or suffix: keyboard doesn't appear. If I tap on the TextField itself - it does appear (again, on the wrong screen though).
So, my questions are:
- Why doesn't it work with TextInput ? (I really need to use TextInput, NOT TextField)
- If there is a way to make it work with TextInput, how to make it work so that the keyboard pops up even when I tap in suffix / prefix?
Thank you.
Column { Rectangle { color: "transparent" border.color: "gray" border.width: 1 radius: 4 width: 500 height: 70 TextInput { id: textField anchors.fill: parent anchors.leftMargin: 10 anchors.rightMargin: 10 } } Rectangle { // my custom element color: "transparent" border.color: "gray" border.width: 1 radius: 4 width: 500 height: 70 MouseArea { anchors.fill: parent hoverEnabled: true onPressed: { textInp.focus = true; textInp.forceActiveFocus()} } RowLayout { anchors.fill: parent spacing: 10 Rectangle { // prefix area color: "lightgray" Layout.minimumWidth: 50 Layout.maximumWidth: 50 Layout.preferredWidth: 50 height: parent.height radius: 4 border.color: "gray" border.width: 1 } TextInput { id: textInp height: parent.height Layout.fillWidth: true } Rectangle { // suffix area color: "lightgray" Layout.minimumWidth: 50 Layout.maximumWidth: 50 Layout.preferredWidth: 50 height: parent.height radius: 4 border.color: "gray" border.width: 1 } } } }