How can i control android device keyboard?
-
How can i control android device keyboard in Qml? Like prevent to closing?
-
You can have (some) control of the keyboard by using
Qt.inputMethod
(documentation: https://doc.qt.io/qt-5/qinputmethod.html) and tweaking focuses throughfocus: true/false
,forceActiveFocus()
in each item. -
@sierdzio On typing, it works great. Pops up the virtual keyboard and when my typing is done, i will be press the enter for onAccepted signal. But i need the change this action for disable closing the keyboard. How can i adapt this enter action on Qml?
-
You mean keyboard should stay visible?
Here's an idea: detect the enter key (you do it in
onAccepted
if I understand you well. An alternative is to useKeys.onPressed
), and in the slot switch focus to some off-screen control. Or, for that matter, switch it back to your current input. The keyboard should stay up this way. -
@Hakan-AFAT have you tried Keys.onReturnPressed to detect the Enter key and then:
https://doc.qt.io/qt-5/qinputmethod.html#show -
I was working on onPressed method QtQuick.Controls2. I got this error, ".onPressed" is not available due to component versioning." on android debug console.
@sierdzio yes, it should stay visible.@ekkescorner i tried this one, too. But TextField signal onAccepted automatically hides the keyboard. Nothing happened with Keys.onReturnPressed. I need modify the onAccepted method on TextField. I found this in qt source, https://code.woboq.org/qt5/qtbase/src/gui/kernel/qinputmethod.cpp.html#214
/* Requests virtual keyboard to close. Normally applications should not need to call this function, keyboard should automatically close when the text editor loses focus,((And if someone press enter)) for example when the parent view is closed. */ void QInputMethod::hide() { Q_D(QInputMethod); QPlatformInputContext *ic = d->platformInputContext(); if (ic) ic->hideInputPanel(); }
-
@Hakan-AFAT if the keyboard closes even if you're switching focus back to the textfield or try to show()
then as a workaround start a Timer to show() or forceActiveFocus()
play with the delay - with some luck you'll find a value where Keyboard stays visible without flicker -
When i put
Qt.inputMethod.show()
in onAccepted method of textfield, it flicker :D. This didn't work.I got same error with "forceActiveFocus". I don't found a correct way to update event on virtual keyboard.
Some testing component in source.
https://code.woboq.org/qt5/qtdeclarative/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp.html#_ZN19tst_qquicktextinput15signal_acceptedEvI changed the textfield to textarea and a new manual enter button solved the problem temporarily.
At this time, text area goes over botttom of screen while i'm typing newline. This crashed too. :D