[Interest] The Android virtual keyboard pushes my main window off the screen
Nikos Chantziaras
realnc at gmail.com
Fri Nov 11 22:57:34 CET 2016
Hello.
I have a serious issue where the virtual keyboard on Android pushes my
whole application off the screen. This happens when the keyboard is
visible and I rotate the device (going to portrait mode or back from it).
Normally, I resize my main window's centralWidget() (using QMainWindow)
when the keyboard size changes:
connect(qApp->inputMethod(), &QInputMethod::keyboardRectangleChanged,
this, [this]
{
auto newSize = size();
newSize.setHeight(height()
- qApp->inputMethod()->keyboardRectangle().height());
centralWidget()->setMaximumSize(newSize);
});
That works fine only as long as the device doesn't change orientation.
When I pop-up the keyboard with:
qApp->inputMethod()->show();
the above code is called and my window adapts its size.
But when I rotate the device while the keyboard is visible, my main
window (and thus the central widget) are pushed upwards, so the top part
of my application isn't visible anymore :-/ The size (QWidget::size())
is still correct, but there's an empty space between the top of the
keyboard and the bottom of my window.
Pressing the "back" button on the device hides the keyboard and brings
the application window back down and makes it visible again. But I need
it to be visible *while* the keyboard is shown.
The position (QWidget::pos()) of the main window and the central widget
are still (0,0) when that happens, and doing a move(0, 0), hoping to
bring them back on-screen doesn't do anything.
How can I keep that from happening? The application becomes useless if
you can't see it on the screen :-/ It seems there's something I need to
do when the device changes orientation? But I don't know what.
More information about the Interest
mailing list