diff options
-rw-r--r-- | src/widgets/kernel/qwidget.cpp | 10 | ||||
-rw-r--r-- | tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp | 17 |
2 files changed, 22 insertions, 5 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 5529f8f72c..2d12674c29 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1362,11 +1362,11 @@ void q_createNativeChildrenAndSetParent(const QWidget *parentWidget) if (!childWidget->internalWinId()) childWidget->winId(); if (childWidget->windowHandle()) { - QWindow *parentWindow = childWidget->nativeParentWidget()->windowHandle(); - if (childWidget->isWindow()) - childWidget->windowHandle()->setTransientParent(parentWindow); - else - childWidget->windowHandle()->setParent(parentWindow); + if (childWidget->isWindow()) { + childWidget->windowHandle()->setTransientParent(parentWidget->window()->windowHandle()); + } else { + childWidget->windowHandle()->setParent(childWidget->nativeParentWidget()->windowHandle()); + } } } else { q_createNativeChildrenAndSetParent(childWidget); diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index ec3e8ece6a..44d7671ca3 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -55,6 +55,7 @@ #include <qmainwindow.h> #include <qdockwidget.h> #include <qtoolbar.h> +#include <qtoolbutton.h> #include <QtGui/qpaintengine.h> #include <QtGui/qbackingstore.h> #include <QtGui/qguiapplication.h> @@ -268,6 +269,7 @@ private slots: void winIdChangeEvent(); void persistentWinId(); void showNativeChild(); + void transientParent(); void qobject_castInDestroyedSlot(); void showHideEvent_data(); @@ -3992,6 +3994,21 @@ void tst_QWidget::persistentWinId() QCOMPARE(w3->winId(), winId3); } +void tst_QWidget::transientParent() +{ + QWidget topLevel; + topLevel.setGeometry(QRect(m_availableTopLeft + QPoint(100, 100), m_testWidgetSize)); + topLevel.setWindowTitle(__FUNCTION__); + QWidget *child = new QWidget(&topLevel); + QMenu *menu = new QMenu(child); // QTBUG-41898: Use top level as transient parent for native widgets as well. + QToolButton *toolButton = new QToolButton(child); + toolButton->setMenu(menu); + toolButton->winId(); + topLevel.show(); + QVERIFY(QTest::qWaitForWindowExposed(&topLevel)); + QCOMPARE(menu->windowHandle()->transientParent(), topLevel.windowHandle()); +} + void tst_QWidget::showNativeChild() { QWidget topLevel; |