From 1ccaae4c1416ce9af8a8426bc17380902000c3cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 4 Jul 2024 17:47:40 +0200 Subject: [PATCH] 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 (cherry picked from commit 6faf18aceb21a4c5e06d0dfe87b9fbaa037f80fd) Reviewed-by: Qt Cherry-pick Bot --- src/android/jar/src/org/qtproject/qt/android/QtWindow.java | 7 +++++++ .../platforms/android/qandroidplatformforeignwindow.cpp | 1 + 2 files changed, 8 insertions(+) diff --git a/src/android/jar/src/org/qtproject/qt/android/QtWindow.java b/src/android/jar/src/org/qtproject/qt/android/QtWindow.java index 135f61d0a02..47b6371ffdb 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtWindow.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtWindow.java @@ -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, diff --git a/src/plugins/platforms/android/qandroidplatformforeignwindow.cpp b/src/plugins/platforms/android/qandroidplatformforeignwindow.cpp index 6bb0081a810..3139114d0a8 100644 --- a/src/plugins/platforms/android/qandroidplatformforeignwindow.cpp +++ b/src/plugins/platforms/android/qandroidplatformforeignwindow.cpp @@ -53,6 +53,7 @@ void QAndroidPlatformForeignWindow::setVisible(bool visible) return; QtAndroid::setViewVisibility(m_view.object(), visible); + m_nativeQtWindow.callMethod("setVisible", visible); if (!visible && m_nativeViewInserted) { m_nativeQtWindow.callMethod("removeNativeView");