Limit typing of characters in android virtual keyboard when using QLineEdit
-
Hello,
Tried searching a lot for some method to limit the typing of characters in a QLineEdit on Android. Using Qt5.15.2. Using QtWidgets for crossplatform compatibility.
I am using QLineEdit, I set the maxlength to say for example 15. WHen I type the characters in android on screen keypad, it lets user type as many characters as they type and truncates to 15 digits on pressing Spacebar or Enter key.
Tried setting the setInputMethodHints(Qt::ImhNoPredictiveText|Qt::ImhNoAutoUppercase|Qt::ImhNoEditMenu);
as I got during my search exercise, but did not work.textChanged signal on this QLineEdit also works only when space or enter is typed and not for each character.
Is there a way to do this? Maybe by using the JNI method?
-
The problem that you described here is related with predictions. Android keyboard have a feature that allows to choose whole ready word rather than type it letter by letter. That's why the typed word is underlined. As the underlined part is still "under construction" and can be changed in any other word (by predictions). This (underlined) part is kept in preeditText - while editText still not changed.
You can just turn predictions off. There are two possibilities to do it:
-
Set inputMethodHints to Qt.ImhNoPredictiveText | Qt.ImhSensitiveData
-
Set QT_ANDROID_ENABLE_WORKAROUND_TO_DISABLE_PREDICTIVE_TEXT environment variable: qputenv("QT_ANDROID_ENABLE_WORKAROUND_TO_DISABLE_PREDICTIVE_TEXT", "1"); )
and inputMethodHints to ImhNoPredictiveText
-
-
These solutions are for QML rather than QWidgets, but still - you can give it a try