From b4db69eee6dc2f381b24aa24586171dbaf8d116e Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 1 Mar 2018 15:30:50 +0100 Subject: Platform: fix checkable MenuItem Update the internal checked state before emitting triggered() Task-number: QTBUG-66386 Change-Id: If120955681b2011bf88126a1ca6032f0af482824 Reviewed-by: Mitch Curtis --- src/imports/platform/qquickplatformmenuitem.cpp | 17 +++++++---------- src/imports/platform/qquickplatformmenuitem_p.h | 1 + 2 files changed, 8 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/imports/platform/qquickplatformmenuitem.cpp b/src/imports/platform/qquickplatformmenuitem.cpp index 61a4daab..bc6d97e1 100644 --- a/src/imports/platform/qquickplatformmenuitem.cpp +++ b/src/imports/platform/qquickplatformmenuitem.cpp @@ -144,10 +144,8 @@ QPlatformMenuItem *QQuickPlatformMenuItem::create() m_handle = QWidgetPlatform::createMenuItem(); if (m_handle) { - connect(m_handle, &QPlatformMenuItem::activated, this, &QQuickPlatformMenuItem::triggered); + connect(m_handle, &QPlatformMenuItem::activated, this, &QQuickPlatformMenuItem::activate); connect(m_handle, &QPlatformMenuItem::hovered, this, &QQuickPlatformMenuItem::hovered); - if (m_checkable) - connect(m_handle, &QPlatformMenuItem::activated, this, &QQuickPlatformMenuItem::toggle); } } return m_handle; @@ -354,13 +352,6 @@ void QQuickPlatformMenuItem::setCheckable(bool checkable) if (m_checkable == checkable) return; - if (m_handle) { - if (checkable) - connect(m_handle, &QPlatformMenuItem::activated, this, &QQuickPlatformMenuItem::toggle); - else - disconnect(m_handle, &QPlatformMenuItem::activated, this, &QQuickPlatformMenuItem::toggle); - } - m_checkable = checkable; sync(); emit checkableChanged(); @@ -602,6 +593,12 @@ QQuickPlatformIconLoader *QQuickPlatformMenuItem::iconLoader() const return m_iconLoader; } +void QQuickPlatformMenuItem::activate() +{ + toggle(); + emit triggered(); +} + void QQuickPlatformMenuItem::updateIcon() { if (!m_handle || !m_iconLoader) diff --git a/src/imports/platform/qquickplatformmenuitem_p.h b/src/imports/platform/qquickplatformmenuitem_p.h index 0c1a7c6d..6ff3ad81 100644 --- a/src/imports/platform/qquickplatformmenuitem_p.h +++ b/src/imports/platform/qquickplatformmenuitem_p.h @@ -161,6 +161,7 @@ protected: QQuickPlatformIconLoader *iconLoader() const; private Q_SLOTS: + void activate(); void updateIcon(); private: -- cgit v1.2.3