Solved TextArea focus pushes view on Android
-
Hello, I've a weird problem on Android. If I click into a TextArea it pushes up my view. First it looked like it only removed the Header component of my Pane but on smaller screen sizes even my content gets "clipped".
Upon showing the TextArea it gets focused (forceActiveFocus) and the Android keyboard is opened but this doesn't do anything disruptive (I can even type into the TextArea), the problem only occurs if I manually click into the TextArea, so it's more than likely not related to the virtual keyboard. Has anyone experienced anything similar before? I searched the docs but I couldn't find anything related.
This is my TextArea code
Rectangle { id: container width: parent.width height: mainWindow.height * 0.2 color: "transparent" anchors.top: elementBefore.bottom anchors.topMargin: contentMargin border.width: 1 border.color: mainWindow.textColor ScrollView { anchors.fill: parent TextArea { id: feedback width: parent.width height: parent.height wrapMode: TextEdit.WordWrap font.pixelSize: 10 * mainWindow.fontSizeMultiplier font.family: noto.name onPressed: { container.border.color = mainWindow.textColor } } } }
Also in the AndroidManifest.xml I'm using "stateUnchanged|adjustPan" which works well on different screens without TextArea.
edit: tested on some other devices, looks like the issue is indeed the virtualkeyboard and the "adjustPan" option
edit2: it's kinda weird, if click in the textarea again, the view "pushing" stops but the virtualkeyboard is still on the screen so again, it might be not related to that
-
That's a pandoras box of a problem, and I really mean it.
You can change "adjustPan" to "adjustResize" in your manifest - then your app will be resized to fit the screen - keyboard size. However, that mode is buggy in Qt - you will see a flicker (screen goes black for a split-second when keyboard is being shown or hidden).
There is a workaround which involves 2 things:
- compile custom Qt for android. You need to patch "QtActivityDelegate.java" file in line 376 - remove x, y parameters and put in 0, 0 for position instead
- handle resizing yourself - because the Qt patch removes screen panning/ resizing completely you need to handle it. If you leave things be, it will still work, but the keyboard will obscure your inputs. To handle screen size changes, take a look into
Qt.inputMethod.keyboardRectangle.height
property
Still, after these changes, you will likely need to test everything and fix other small bugs - because on some phones (especially LG devices) the
keyboardRectangle
is not updated correctly :-(Lastly, sorry that I won't post exact patch and code that I have for this, but I can't (NDA).
-
@sierdzio I've been actually doing something similar up to now but using
doInputMethodVisibleChanged
(so I get no exact virtual keyboard size but it's something) and it was working fine (no screen pushes) the paning I experienced happened on another (more complex) screen with the TextArea, thats why I thought it was something TextArea specific.Thanks for the 2 possible solutions, if someone complains about my current hacky workaround I'll give those a try!
-
@sierdzio said in TextArea focus pushes view on Android:
You can change "adjustPan" to "adjustResize" in your manifest - then your app will be resized to fit the screen - keyboard size. However, that mode is buggy in Qt - you will see a flicker (screen goes black for a split-second when keyboard is being shown or hidden).
Self quoting ;-) But there is also another option here - to fix that flicker. For reference, here's the report about it https://bugreports.qt.io/browse/QTBUG-41170
I've tried fixing it and got something that worked a bit better - the flicker was still there but shorter and less obvious. But it was not a complete, good fix and I didn't have the time to push it further. I may come back to it at some point in the future, but if you have the time and will to do it, feel free to go ahead :-) Whole Qt community will benefit from such a fix. The code responsible lies in QPA plugin for Android, and has something to do with the fact that Qt constructs a brand new EGL surface when screen is resized - as far as I can tell such restart is completely unnecessary.