Android/Embedding QML: Resize also parent window

The parent window created from the QtView had an
empty size. Also set its size when creating the window,
and when resizing the QtView. Replace parent window show()
call with showNormal() to avoid switching it to a fullscreen
window.

As a drive-by, use setGeometry() instead of setting the width
and height separately to trigger only one geometry update
for the platform window.

Change-Id: I91e350c1748a9e76879faa8bfcab7575f6155f02
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
(cherry picked from commit e9edd3db524e0c9c77925ae5bea98017a6220ecf)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tinja Paavoseppä 2024-03-27 13:42:05 +02:00 committed by Qt Cherry-pick Bot
parent 7da0c6f83e
commit 939bfb838e
3 changed files with 11 additions and 8 deletions

View File

@ -30,7 +30,7 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS
private QtNative.ApplicationStateDetails m_stateDetails; private QtNative.ApplicationStateDetails m_stateDetails;
private boolean m_windowLoaded = false; 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); static native void deleteWindow(long windowReference);
public QtEmbeddedDelegate(Activity context) { public QtEmbeddedDelegate(Activity context) {
@ -159,7 +159,7 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS
private void createRootWindow() { private void createRootWindow() {
if (m_view != null && !m_windowLoaded) { if (m_view != null && !m_windowLoaded) {
createRootWindow(m_view); createRootWindow(m_view, m_view.getWidth(), m_view.getHeight());
m_windowLoaded = true; m_windowLoaded = true;
} }
} }

View File

@ -15,12 +15,13 @@ Q_DECLARE_JNI_CLASS(QtView, "org/qtproject/qt/android/QtView");
Q_DECLARE_JNI_CLASS(QtEmbeddedDelegate, "org/qtproject/qt/android/QtEmbeddedDelegate"); Q_DECLARE_JNI_CLASS(QtEmbeddedDelegate, "org/qtproject/qt/android/QtEmbeddedDelegate");
namespace QtAndroidWindowEmbedding { 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 // QWindow should be constructed on the Qt thread rather than directly in the caller thread
// To avoid hitting checkReceiverThread assert in QCoreApplication::doNotify // To avoid hitting checkReceiverThread assert in QCoreApplication::doNotify
QMetaObject::invokeMethod(qApp, [rootView] { QMetaObject::invokeMethod(qApp, [rootView, width, height] {
QWindow *parentWindow = QWindow::fromWinId(reinterpret_cast<WId>(rootView.object())); QWindow *parentWindow = QWindow::fromWinId(reinterpret_cast<WId>(rootView.object()));
parentWindow->setGeometry(0, 0, width, height);
rootView.callMethod<void>("createWindow", reinterpret_cast<jlong>(parentWindow)); rootView.callMethod<void>("createWindow", reinterpret_cast<jlong>(parentWindow));
}); });
} }
@ -38,7 +39,7 @@ namespace QtAndroidWindowEmbedding {
if (visible) { if (visible) {
window->showNormal(); window->showNormal();
if (!window->parent()->isVisible()) if (!window->parent()->isVisible())
window->parent()->show(); window->parent()->showNormal();
} else { } else {
window->hide(); window->hide();
} }
@ -48,8 +49,10 @@ namespace QtAndroidWindowEmbedding {
void resizeWindow(JNIEnv *, jclass, jlong windowRef, jint width, jint height) void resizeWindow(JNIEnv *, jclass, jlong windowRef, jint width, jint height)
{ {
QWindow *window = reinterpret_cast<QWindow*>(windowRef); QWindow *window = reinterpret_cast<QWindow*>(windowRef);
window->setWidth(width); QWindow *parent = window->parent();
window->setHeight(height); if (parent)
parent->setGeometry(0, 0, width, height);
window->setGeometry(0, 0, width, height);
} }
bool registerNatives(QJniEnvironment& env) { bool registerNatives(QJniEnvironment& env) {

View File

@ -25,7 +25,7 @@ Q_DECLARE_JNI_CLASS(View, "android/view/View");
namespace QtAndroidWindowEmbedding namespace QtAndroidWindowEmbedding
{ {
bool registerNatives(QJniEnvironment& env); 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) Q_DECLARE_JNI_NATIVE_METHOD_IN_CURRENT_SCOPE(createRootWindow)
void deleteWindow(JNIEnv *, jclass, jlong window); void deleteWindow(JNIEnv *, jclass, jlong window);
Q_DECLARE_JNI_NATIVE_METHOD_IN_CURRENT_SCOPE(deleteWindow) Q_DECLARE_JNI_NATIVE_METHOD_IN_CURRENT_SCOPE(deleteWindow)