How to set returnKeyType for Android Virtual Keyboard
-
Hello All! First post here.
First, my environment: Android 5.x, Qt 5.3.1, QML application
I've been watching the BugTracker here: https://bugreports.qt.io/browse/QTBUG-39074
I am really looking forward to this functionality coming in, but my project must deliver before it will be merged. A few of the comments on the bugtracker seemed to give me some good ideas on workarounds, but after spending a couple of full days researching and reading the Qt code-base, I am still having a hard time understanding this. I've pasted the relevant comments below:====================================================
Tor Arne Vestbø added a comment - Yesterday
A completely unsupported workaround is to set the 'returnKeyType' key of a QVariantMap that you assign to the platformData of the IM hints.Corey Pendleton added a comment - Yesterday - edited
That's awesome! Thank you for the idea!
Acknowledging that this is "completely unsupported" I am exploring this workaround until we can pull up and gain the fix from this bug report.I have one question:
I see the platform data for the InputMethodQuery enum. But it seems that I would need to override inputMethodQuery() in order to provide the QVariantMap you mention back to the VKB. Since QQuickTextEdit is private and I cannot inherit from it, does this mean implementing my own text input component or is there some other way to assign the value that I want to be returned for a platform data query?Pekka Vuorela added a comment - 10 hours ago
You can signal changes with ImPlatformData but fetch the new state with some alternative method, e.g. QObject property on the focused editor. That way you can continue using common editor components.I have found the handlers in QQuickItem. I have also found in QInputMethod that I can call update and pass the Input Method Query type of ImPlatformData effectively telling the virutal inputMethod that the platform data has changed.. however I cannot see what these kind commenters mean when they say I can "fetch the new state with an alternative method" or "assign a QVariantMap to the platformData". As far as I can tell, when the update method is called, it queries the focused item for the new platformData using inputMethodQuery() which I cannot override for a QML TextEdit item.
Any advice or clarification would be much appreciated. I would really like to understand the data flow between InputMethod and FocusedItem better as a whole.
-
I've been experimenting further and reading through the source code. Again, I still only see the inputMethodQuery and inputMethodEvent functions as entry points to potentially return a QVariantMap with a "returnKeyType" property, and neither one can be overridden.
I tried creating an inline function in my QML code for a TextEdit/TextInput, but the meta method created has a QVariant parameter instead of a Qt::InputMethodQuery, so the logic from QInputMethod does not go through this function.
It looks like the android code completely ignores the ImPlatformData value (at least as of Qt 5.3.1 where I am based). It may be that this was only ever handled in iOS logic previously? If that is the case, then I will have to abandon this effort and wait for Qt 5.6 to come in with native support for returnKeyType. Unfortunately, that will be too late for this project release.