diff options
-rw-r--r-- | src/controls/qquickmenu.cpp | 17 | ||||
-rw-r--r-- | src/controls/qquickmenu_p.h | 2 |
2 files changed, 19 insertions, 0 deletions
diff --git a/src/controls/qquickmenu.cpp b/src/controls/qquickmenu.cpp index b725bbbf..3c243ba3 100644 --- a/src/controls/qquickmenu.cpp +++ b/src/controls/qquickmenu.cpp @@ -436,6 +436,10 @@ void QQuickMenu1::__popup(const QRectF &targetRect, int atItemIndex, MenuType me // parentWindow may not be a QQuickWindow (happens when using QQuickWidget) if (m_platformMenu) { + if (m_windowConnection) + QObject::disconnect(m_windowConnection); + m_windowConnection = connect(parentWindow, &QWindow::visibleChanged, this, + &QQuickMenu1::platformMenuWindowVisibleChanged, Qt::UniqueConnection); QRectF globalTargetRect = targetRect.translated(m_xOffset, m_yOffset); if (visualItem()) { if (qGuiApp->isRightToLeft()) { @@ -565,6 +569,19 @@ void QQuickMenu1::windowVisibleChanged(bool v) } } +void QQuickMenu1::platformMenuWindowVisibleChanged(bool visible) +{ + if (!visible) { + if (m_windowConnection) { + QObject::disconnect(m_windowConnection); + m_windowConnection = QMetaObject::Connection(); + } + if (m_platformMenu) { + m_platformMenu->dismiss(); + } + } +} + void QQuickMenu1::clearPopupWindow() { m_popupWindow = 0; diff --git a/src/controls/qquickmenu_p.h b/src/controls/qquickmenu_p.h index 576ae5fd..8510efbe 100644 --- a/src/controls/qquickmenu_p.h +++ b/src/controls/qquickmenu_p.h @@ -165,6 +165,7 @@ protected Q_SLOTS: void updateText(); void windowVisibleChanged(bool); + void platformMenuWindowVisibleChanged(bool); private: QQuickWindow *findParentWindow(); @@ -205,6 +206,7 @@ private: QFont m_font; int m_triggerCount; bool m_proxy; + QMetaObject::Connection m_windowConnection; }; QT_END_NAMESPACE |