diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 68715413d17..cb2e9e0becd 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -12272,7 +12272,7 @@ QPoint QWidget::mapToGlobal(const QPoint &pos) const { #ifndef QT_NO_GRAPHICSVIEW Q_D(const QWidget); - if (d->extra && d->extra->proxyWidget) { + if (d->extra && d->extra->proxyWidget && d->extra->proxyWidget->scene()) { const QList views = d->extra->proxyWidget->scene()->views(); if (!views.isEmpty()) { const QPointF scenePos = d->extra->proxyWidget->mapToScene(pos); @@ -12307,7 +12307,7 @@ QPoint QWidget::mapFromGlobal(const QPoint &pos) const { #ifndef QT_NO_GRAPHICSVIEW Q_D(const QWidget); - if (d->extra && d->extra->proxyWidget) { + if (d->extra && d->extra->proxyWidget && d->extra->proxyWidget->scene()) { const QList views = d->extra->proxyWidget->scene()->views(); if (!views.isEmpty()) { const QPoint viewPortPos = views.first()->viewport()->mapFromGlobal(pos); diff --git a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp index 5aea845f90d..3913f204ba3 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp @@ -175,6 +175,7 @@ private slots: void windowFrameMargins(); void QTBUG_6986_sendMouseEventToAlienWidget(); void mapToGlobal(); + void mapToGlobalWithoutScene(); void QTBUG_43780_visibility(); }; @@ -3690,6 +3691,16 @@ void tst_QGraphicsProxyWidget::mapToGlobal() // QTBUG-41135 .arg(embeddedCenterGlobal.x()).arg(embeddedCenterGlobal.y()))); } +void tst_QGraphicsProxyWidget::mapToGlobalWithoutScene() // QTBUG-44509 +{ + QGraphicsProxyWidget proxyWidget; + QWidget *embeddedWidget = new QWidget; + proxyWidget.setWidget(embeddedWidget); + const QPoint localPos(0, 0); + const QPoint globalPos = embeddedWidget->mapToGlobal(localPos); + QCOMPARE(embeddedWidget->mapFromGlobal(globalPos), localPos); +} + // QTBUG_43780: Embedded widgets have isWindow()==true but showing them should not // trigger the top-level widget code path of show() that closes all popups // (for example combo popups).