summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@digia.com>2014-09-09 17:11:03 +0200
committerJani Heikkinen <jani.heikkinen@digia.com>2014-09-10 11:56:17 +0200
commitd70e5ebe11a8eb22fe5e71945982d81991dc9f09 (patch)
tree81dde5c8b680fce109d35904e40dfb7206dc4619
parentbc91574cca8b6f24968ab4e1cc11fe1fd10f3061 (diff)
downloadqtquickcontrols-5.3.2.tar.gz
Fix menu popups positioning with window containersv5.3.25.3.2
Task-number: QTBUG-40883 Change-Id: I5c46c049b5890259d65f325adb59e15ebf29f84a Reviewed-by: Robert Loehning <robert.loehning@digia.com> Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
-rw-r--r--src/controls/qquickmenupopupwindow.cpp11
-rw-r--r--src/controls/qquickmenupopupwindow_p.h1
-rw-r--r--src/controls/qquickpopupwindow.cpp19
3 files changed, 16 insertions, 15 deletions
diff --git a/src/controls/qquickmenupopupwindow.cpp b/src/controls/qquickmenupopupwindow.cpp
index e07a41d6..bdd1cd6b 100644
--- a/src/controls/qquickmenupopupwindow.cpp
+++ b/src/controls/qquickmenupopupwindow.cpp
@@ -50,8 +50,10 @@
QT_BEGIN_NAMESPACE
QQuickMenuPopupWindow::QQuickMenuPopupWindow() :
- QQuickPopupWindow(), m_itemAt(0)
-{ }
+ m_itemAt(0),
+ m_logicalParentWindow(0)
+{
+}
void QQuickMenuPopupWindow::show()
{
@@ -59,6 +61,10 @@ void QQuickMenuPopupWindow::show()
// show() will reposition the popup at the last moment,
// so its initial position must be captured after the call.
m_initialPos = position();
+ if (m_logicalParentWindow && m_logicalParentWindow->parent()) {
+ // This must be a QQuickWindow embedded via createWindowContainer.
+ m_initialPos += m_logicalParentWindow->geometry().topLeft();
+ }
}
void QQuickMenuPopupWindow::setParentItem(QQuickItem *item)
@@ -92,6 +98,7 @@ void QQuickMenuPopupWindow::setParentWindow(QWindow *effectiveParentWindow, QQui
effectiveParentWindow = effectiveParentWindow->parent();
if (transientParent() != effectiveParentWindow)
setTransientParent(effectiveParentWindow);
+ m_logicalParentWindow = parentWindow;
if (parentWindow) {
connect(parentWindow, SIGNAL(destroyed()), this, SLOT(dismissPopup()));
if (QQuickMenuPopupWindow *pw = qobject_cast<QQuickMenuPopupWindow *>(parentWindow))
diff --git a/src/controls/qquickmenupopupwindow_p.h b/src/controls/qquickmenupopupwindow_p.h
index a550daa2..7da861d9 100644
--- a/src/controls/qquickmenupopupwindow_p.h
+++ b/src/controls/qquickmenupopupwindow_p.h
@@ -69,6 +69,7 @@ private:
QQuickItem *m_itemAt;
QPointF m_oldItemPos;
QPointF m_initialPos;
+ QQuickWindow *m_logicalParentWindow;
};
QT_END_NAMESPACE
diff --git a/src/controls/qquickpopupwindow.cpp b/src/controls/qquickpopupwindow.cpp
index eefeadb7..fe697d31 100644
--- a/src/controls/qquickpopupwindow.cpp
+++ b/src/controls/qquickpopupwindow.cpp
@@ -68,23 +68,16 @@ void QQuickPopupWindow::show()
{
qreal posx = x();
qreal posy = y();
- if (QQuickWindow *parentWindow = qobject_cast<QQuickWindow *>(transientParent())) {
+ // transientParent may not be a QQuickWindow when embedding into widgets
+ if (QWindow *tp = transientParent()) {
if (m_parentItem) {
- QPointF pos = m_parentItem->mapToItem(parentWindow->contentItem(), QPointF(posx, posy));
+ QPointF pos = m_parentItem->mapToItem(m_parentItem->window()->contentItem(), QPointF(posx, posy));
posx = pos.x();
posy = pos.y();
}
-
- 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();
- }
+ QPoint tlwOffset = tp->mapToGlobal(QPoint());
+ posx += tlwOffset.x();
+ posy += tlwOffset.y();
} else if (m_parentItem && m_parentItem->window()) {
QPoint offset;
QQuickWindow *quickWindow = m_parentItem->window();