diff --git a/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java b/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java index cbf715ab19f..eb17ab680eb 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java @@ -30,7 +30,7 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS private QtNative.ApplicationStateDetails m_stateDetails; private boolean m_windowLoaded = false; - private static native void createRootWindow(View rootView); + private static native void createRootWindow(View rootView, int width, int height); static native void deleteWindow(long windowReference); public QtEmbeddedDelegate(Activity context) { @@ -159,7 +159,7 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS private void createRootWindow() { if (m_view != null && !m_windowLoaded) { - createRootWindow(m_view); + createRootWindow(m_view, m_view.getWidth(), m_view.getHeight()); m_windowLoaded = true; } } diff --git a/src/plugins/platforms/android/androidwindowembedding.cpp b/src/plugins/platforms/android/androidwindowembedding.cpp index e72bb326ccc..40c5b3c95f6 100644 --- a/src/plugins/platforms/android/androidwindowembedding.cpp +++ b/src/plugins/platforms/android/androidwindowembedding.cpp @@ -15,12 +15,13 @@ Q_DECLARE_JNI_CLASS(QtView, "org/qtproject/qt/android/QtView"); Q_DECLARE_JNI_CLASS(QtEmbeddedDelegate, "org/qtproject/qt/android/QtEmbeddedDelegate"); namespace QtAndroidWindowEmbedding { - void createRootWindow(JNIEnv *, jclass, QtJniTypes::View rootView) + void createRootWindow(JNIEnv *, jclass, QtJniTypes::View rootView, jint width, jint height) { // QWindow should be constructed on the Qt thread rather than directly in the caller thread // To avoid hitting checkReceiverThread assert in QCoreApplication::doNotify - QMetaObject::invokeMethod(qApp, [rootView] { + QMetaObject::invokeMethod(qApp, [rootView, width, height] { QWindow *parentWindow = QWindow::fromWinId(reinterpret_cast(rootView.object())); + parentWindow->setGeometry(0, 0, width, height); rootView.callMethod("createWindow", reinterpret_cast(parentWindow)); }); } @@ -38,7 +39,7 @@ namespace QtAndroidWindowEmbedding { if (visible) { window->showNormal(); if (!window->parent()->isVisible()) - window->parent()->show(); + window->parent()->showNormal(); } else { window->hide(); } @@ -48,8 +49,10 @@ namespace QtAndroidWindowEmbedding { void resizeWindow(JNIEnv *, jclass, jlong windowRef, jint width, jint height) { QWindow *window = reinterpret_cast(windowRef); - window->setWidth(width); - window->setHeight(height); + QWindow *parent = window->parent(); + if (parent) + parent->setGeometry(0, 0, width, height); + window->setGeometry(0, 0, width, height); } bool registerNatives(QJniEnvironment& env) { diff --git a/src/plugins/platforms/android/androidwindowembedding.h b/src/plugins/platforms/android/androidwindowembedding.h index 4f3261a30bd..cb0e5f90cea 100644 --- a/src/plugins/platforms/android/androidwindowembedding.h +++ b/src/plugins/platforms/android/androidwindowembedding.h @@ -25,7 +25,7 @@ Q_DECLARE_JNI_CLASS(View, "android/view/View"); namespace QtAndroidWindowEmbedding { bool registerNatives(QJniEnvironment& env); - void createRootWindow(JNIEnv *, jclass, QtJniTypes::View rootView); + void createRootWindow(JNIEnv *, jclass, QtJniTypes::View rootView, jint width, jint height); Q_DECLARE_JNI_NATIVE_METHOD_IN_CURRENT_SCOPE(createRootWindow) void deleteWindow(JNIEnv *, jclass, jlong window); Q_DECLARE_JNI_NATIVE_METHOD_IN_CURRENT_SCOPE(deleteWindow)