From 87b603080a300f865643a7c6c2c62a5cc795343b Mon Sep 17 00:00:00 2001
From: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
Date: Thu, 13 Jun 2013 16:23:50 +0200
Subject: [PATCH] Menu: Support QQuickWindows embedded in QWidgets

We translate the menu popup window by its transient parent origin
coordinates, but if it's embedded in a QWidget, we would only translate
by the transient parent's origin inside that QWidget. So, in this case.
we translate by the transient parent's origin in the global coordinate
reference system.

Task-number: QTBUG-31659
Change-Id: I09aa64f2d61d227d4fcd6d6e22a25453e1f2dc76
Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
---
 src/controls/qquickmenupopupwindow.cpp | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/controls/qquickmenupopupwindow.cpp b/src/controls/qquickmenupopupwindow.cpp
index a8f2a153c..b44b082cf 100644
--- a/src/controls/qquickmenupopupwindow.cpp
+++ b/src/controls/qquickmenupopupwindow.cpp
@@ -66,8 +66,16 @@ void QQuickMenuPopupWindow::show()
             posy = pos.y();
         }
 
-        posx += parentWindow->geometry().left();
-        posy += parentWindow->geometry().top();
+        if (parentWindow->parent()) {
+            // If the parent window is embedded in another window, the offset needs to be relative to
+            // its top-level window container, or to global coordinates, which is the same in the end.
+            QPoint parentWindowOffset = parentWindow->mapToGlobal(QPoint());
+            posx += parentWindowOffset.x();
+            posy += parentWindowOffset.y();
+        } else {
+            posx += parentWindow->geometry().left();
+            posy += parentWindow->geometry().top();
+        }
     }
 
     if (m_itemAt) {
-- 
GitLab