Android: Create QtWindow as initially hidden

QWindows are not visible when created, and require a setVisible(true)
call to be be shown. Android Views on the other hand are visible by
default.

This mismatch caused problems when a foreign window was parented into
a QWindow that was yet to be shown. If the foreign window child was shown,
it would show up on screen, due to its QtWindow parent, as well as the
parent window's QtWindow both being visible.

Technically this problem also applied to normal Qt child windows, but
because these windows rarely render unless isExposed() returns true
they would not show anything.

We now initialize QtWindow to being hidden on creation, and let QWindow
handle the order of when the window is made visible.

The QAndroidPlatformForeignWindow::setVisible code had to be adjusted,
as it doesn't call into the QAndroidPlatformWindow base class, where
we normally handle the visibility toggling of our QtWindow layout.

Change-Id: I3debba5f42609d687dc88f7f92c89055cfa6c5f1
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
(cherry picked from commit 6faf18aceb21a4c5e06d0dfe87b9fbaa037f80fd)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tor Arne Vestbø 2024-07-04 17:47:40 +02:00 committed by Qt Cherry-pick Bot
parent c9dcb28824
commit 1ccaae4c14
2 changed files with 8 additions and 0 deletions

View File

@ -33,6 +33,13 @@ class QtWindow extends QtLayout implements QtSurfaceInterface {
setParent(parentWindow);
setFocusableInTouchMode(true);
// Views are by default visible, but QWindows are not.
// We should ideally pick up the actual QWindow state here,
// but QWindowPrivate::setVisible() expects to control the
// order of events tightly, so we need to wait for a call
// to QAndroidPlatformWindow::setVisible().
setVisible(false);
if (!isForeignWindow) {
m_editText = new QtEditText(context, listener);
addView(m_editText, new QtLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,

View File

@ -53,6 +53,7 @@ void QAndroidPlatformForeignWindow::setVisible(bool visible)
return;
QtAndroid::setViewVisibility(m_view.object(), visible);
m_nativeQtWindow.callMethod<void>("setVisible", visible);
if (!visible && m_nativeViewInserted) {
m_nativeQtWindow.callMethod<void>("removeNativeView");