diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2023-12-06 17:53:59 +0100 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2023-12-06 21:25:19 +0100 |
commit | 11e524d0ccfeda9ee0e4b60ad6e14a58cc8d9037 (patch) | |
tree | ef6a38c821ebecf0cab79b8336739d8c6b933b1a /src/gui/kernel/qwindow.cpp | |
parent | fa79b56bd82df6852aab6819dc31b359ee7b24e7 (diff) |
Avoid QWindow crashing in mapToGlobal when no platformWindow
Add f60fb8f41741c2ca4dbd02b70d56e561be64d673 also to mapToGlobal.
Amends 67fa2585ac48e64972d1c0a20b3add5c3ef72e51
Avoids crashing in certain applications that use QQuickRenderControl
and QQuickWindows that are not backed by a QPlatformWindow.
Change-Id: Ie4a8bd7837973e7997f9b668f776ca2999147d75
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/gui/kernel/qwindow.cpp')
-rw-r--r-- | src/gui/kernel/qwindow.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 178b1f51e5..9de6148046 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -2850,7 +2850,12 @@ QPointF QWindow::mapToGlobal(const QPointF &pos) const // Map the position (and the window's global position) to native coordinates, perform // the addition, and then map back to device independent coordinates. QPointF nativeLocalPos = QHighDpi::toNativeLocalPosition(pos, this); - QPointF nativeWindowGlobalPos = d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF(); + // Get the native window position directly from the platform window + // if available (it can be null if the window hasn't been shown yet), + // or fall back to scaling the QWindow position. + QPointF nativeWindowGlobalPos = d->platformWindow + ? d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF() + : QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()), this); QPointF nativeGlobalPos = nativeLocalPos + nativeWindowGlobalPos; QPointF deviceIndependentGlobalPos = QHighDpi::fromNativeGlobalPosition(nativeGlobalPos, this); return deviceIndependentGlobalPos; |