From d5a01cdf6e762f510e0b70e3be95998f16ebaf40 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Thu, 28 May 2020 08:41:31 +0200 Subject: Sync the QQuickPlatformMenu so it has a handle ready when its a sub menu When dynamically creating a menu, it will be parented after it has created the handle the first time around. Therefore it loses the original handle and does not get a new one when needed. So by calling sync() before it is set as the sub menu then it can get a handle created if necessary in time. Change-Id: Ia39f49f99758802dd19ff1df478b05ac5e403ea8 Reviewed-by: Mitch Curtis (cherry picked from commit 7640c9988f37e49e12f56be7a30ea97170922b9f) Reviewed-by: Qt Cherry-pick Bot --- src/imports/platform/qquickplatformmenuitem.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/imports/platform/qquickplatformmenuitem.cpp b/src/imports/platform/qquickplatformmenuitem.cpp index a1f17aa4..44f38e0f 100644 --- a/src/imports/platform/qquickplatformmenuitem.cpp +++ b/src/imports/platform/qquickplatformmenuitem.cpp @@ -166,8 +166,13 @@ void QQuickPlatformMenuItem::sync() m_handle->setText(m_text); m_handle->setFont(m_font); m_handle->setHasExclusiveGroup(m_group && m_group->isExclusive()); - if (m_subMenu && m_subMenu->handle()) - m_handle->setMenu(m_subMenu->handle()); + if (m_subMenu) { + // Sync first as dynamically created menus may need to get the + // handle recreated + m_subMenu->sync(); + if (m_subMenu->handle()) + m_handle->setMenu(m_subMenu->handle()); + } #if QT_CONFIG(shortcut) QKeySequence sequence; -- cgit v1.2.3