Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt Android: Virtual keyboard keeps switching to uppercase when I type in a QLineEdit

When I type in a QLineEdit, the virtual keyboard starts with uppercase. Even if I set it to lowercase, it returns to uppercase as soon as I've typed a single character. That is, every time I type a character, the keyboard is reset to uppercase again.

This happens even on a freshly created project (I just put a line edit and run it).

I found a forum thread about the same issue - https://groups.google.com/forum/#!topic/android-qt/QMFZmkACAIA.

I'm using Qt/C++ (not QML).

Edit: Just tested it on a new QML project, the bug is there too. I also found a thread posted about it for QML - https://groups.google.com/forum/#!msg/android-qt/BzGDGoLNtYc/TdtOX9MW3vIJ.

Edit 2: I tested with inputMethodHints(), and the only one that had effect was ImhNoAutoUppercase. But then it still started with an uppercase char, and when pressing the back button (to delete the last character), the keyboard will switch to uppercase again, even if you've typed several letters. After the first letter it switches to lowercase, and if you don't press the back button it works mostly OK.

like image 599
sashoalm Avatar asked Aug 12 '14 11:08

sashoalm


1 Answers

Edit: A somewhat good workaround is setting ImhNoAutoUppercase, the first letter is still capitalized, but at least the next letters you type will be lowercase.

Original answer: In Android, this would be set using inputType on the EditText in the xml of the layout file for the Activity/Fragment (screen/page you are looking at). Can you access and edit the layout file directly for Android?

Are you using setInputMask() to control the input type? It may be that forcing lowercase (or switching of case conversion) gives the option to use upper or lower case. I guess what is being set in the Android layout xml file is inputType="textCapSentences" or something similar ( https://developer.android.com/training/keyboard-input/style.html ).

UPDATE: You mention that the issue is fixed in 5.4. This looks like the commit that would fix it. I would suggest just implementing the fixes shown here. https://qt.gitorious.org/qt/qtbase/commit/2b3f293d892c5268bd2a07ed17fa9fc5adacbd76

You mention you are happy to edit the Qt source code. I think the error may be in this part of src/org/qtproject/qt5/android/QtActivityDelegate.java

        if ((inputHints & ImhUppercaseOnly) != 0) {
            initialCapsMode |= android.text.TextUtils.CAP_MODE_CHARACTERS;
            inputType |= android.text.InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS;
        } else if ((inputHints & ImhLowercaseOnly) == 0 && (inputHints & ImhNoAutoUppercase) == 0) {
            initialCapsMode |= android.text.TextUtils.CAP_MODE_SENTENCES;
            inputType |= android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; 
        }

Should be changed to:

        if ((inputHints & ImhUppercaseOnly) != 0) {
            initialCapsMode |= android.text.TextUtils.CAP_MODE_CHARACTERS;
            inputType |= android.text.InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS;
        } else if ((inputHints & ImhLowercaseOnly) == 0 && (inputHints & ImhNoAutoUppercase) == 0) {
            //initialCapsMode |= android.text.TextUtils.CAP_MODE_SENTENCES; // not sure what to set here - could try 0 or null if commenting out line doesn't work
            inputType |= android.text.InputType.TYPE_CLASS_TEXT; 
        }

If this doesn't fix it, I'd suggest searching the source code for android.text.InputType.TYPE_TEXT_FLAG_CAP or android.text.TextUtils.CAP_MODE and replacing them by trial and error.

like image 104
TTransmit Avatar answered Oct 24 '22 05:10

TTransmit