Fix problem with subFocusItem on non-OpenGL QSG

The subFocusItem state was forgotten because the old parent was deleted,
before its focused child was reparented.

The test doesn't pass on Android and makes the test process exit with
error. Since it prints warnings that indicate issues further down in
the RHI stack, we'll skip it for now on that platform.

Task-number: QTBUG-112696
Pick-to: 6.5 6.2
Change-Id: Ibb32a11564ff6fbb2091c241d508f12479b234b0
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Allan Sandfeld Jensen 2023-04-05 17:12:07 +02:00 committed by Volker Hilsheimer
parent e1402abff9
commit 30e46e37a3
2 changed files with 46 additions and 1 deletions

View File

@ -241,7 +241,7 @@ void QQuickWidgetPrivate::handleWindowChange()
// must be recreated because its RHI will contain a dangling pointer to
// the context.
delete offscreenWindow;
QScopedPointer<QQuickWindow> oldOffScreenWindow(offscreenWindow); // Do not delete before reparenting sgItem
offscreenWindow = nullptr;
delete renderControl;

View File

@ -23,6 +23,7 @@
#include <QtGui/qstylehints.h>
#include <QtWidgets/QBoxLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/private/qapplication_p.h>
#include <QtQuickWidgets/QQuickWidget>
@ -135,6 +136,7 @@ private slots:
#if QT_CONFIG(graphicsview)
void focusOnClickInProxyWidget();
#endif
void focusPreserved();
private:
QPointingDevice *device = QTest::createTouchDevice();
@ -939,6 +941,49 @@ void tst_qquickwidget::focusOnClickInProxyWidget()
}
#endif
void tst_qquickwidget::focusPreserved()
{
if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation))
QSKIP("Window Activation is not supported.");
if (QGuiApplication::platformName() == "android")
QSKIP("Test doesn't exit cleanly on Android and generates many warnings - QTBUG-112696");
QScopedPointer<QWidget> widget(new QWidget());
QScopedPointer<QQuickWidget> quick(new QQuickWidget());
QQuickItem *root = new QQuickItem(); // will be owned by quick after setContent
QScopedPointer<QQuickItem> content(new QQuickItem());
content->setActiveFocusOnTab(true);
content->setFocus(true);
quick->setFocusPolicy(Qt::StrongFocus);
quick->setContent(QUrl(), nullptr, root);
root->setFlag(QQuickItem::ItemHasContents);
content->setParentItem(root);
quick->setGeometry(0, 0, 200, 200);
quick->show();
quick->setFocus();
quick->activateWindow();
QVERIFY(QTest::qWaitForWindowExposed(quick.get()));
QTRY_VERIFY(quick->hasFocus());
QTRY_VERIFY(content->hasFocus());
QTRY_VERIFY(content->hasActiveFocus());
widget->show();
widget->setFocus();
widget->activateWindow();
QVERIFY(QTest::qWaitForWindowExposed(widget.get()));
QTRY_VERIFY(widget->hasFocus());
quick->setParent(widget.get());
quick->show();
quick->setFocus();
quick->activateWindow();
QTRY_VERIFY(quick->hasFocus());
QTRY_VERIFY(content->hasFocus());
QTRY_VERIFY(content->hasActiveFocus());
}
QTEST_MAIN(tst_qquickwidget)
#include "tst_qquickwidget.moc"