aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2018-07-30 14:28:44 +0200
committerMitch Curtis <mitch.curtis@qt.io>2019-02-04 10:43:52 +0000
commitec8952cec9b44e7ab77c5450d8d6fb6579c21555 (patch)
tree735ab8348426737b6d3db5dd859a805ca72b4795 /src/quicktemplates2
parent09181d8b61cf3c84c88258586d68bd721d440620 (diff)
Fix Menu not being dismissed when the triggered item disables itself
Problem Consider the following code: Menu { title: "Menu" Action { text: "Item" onTriggered: enabled = false } } A MenuItem (AbstractButton) is created for the Action, and when it is clicked, this function is called: void QQuickAbstractButtonPrivate::trigger() { Q_Q(QQuickAbstractButton); if (action && action->isEnabled()) QQuickActionPrivate::get(action)->trigger(q, false); else if (effectiveEnable) emit q->clicked(); } QQuickActionPrivate::get(action)->trigger(q, false) results in this function being called: void QQuickAbstractButtonPrivate::click() { Q_Q(QQuickAbstractButton); if (effectiveEnable) emit q->clicked(); } Since the action (and hence the menu item) was disabled in the signal handler, the effectiveEnable check fails and clicked() is not emitted. This causes the menu to not be dismissed. Solution Before calling QQuickActionPrivate::get(action)->trigger(), store the button's enabled state. If triggering the action causes the action to be disabled (due to the signal handler), we can then choose whether or not we emit QQuickAbstractButton::clicked(). Specifically, we emit clicked() if: - we were enabled before triggering the action, and - we have no associated action, or it's no longer enabled Task-number: QTBUG-69682 Change-Id: Ib4e3c313b776decc74089a6beffe415605c430be Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/quicktemplates2')
-rw-r--r--src/quicktemplates2/qquickabstractbutton.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/quicktemplates2/qquickabstractbutton.cpp b/src/quicktemplates2/qquickabstractbutton.cpp
index 9157b4f9..3b41f34c 100644
--- a/src/quicktemplates2/qquickabstractbutton.cpp
+++ b/src/quicktemplates2/qquickabstractbutton.cpp
@@ -324,9 +324,10 @@ void QQuickAbstractButtonPrivate::click()
void QQuickAbstractButtonPrivate::trigger()
{
Q_Q(QQuickAbstractButton);
+ const bool wasEnabled = effectiveEnable;
if (action && action->isEnabled())
QQuickActionPrivate::get(action)->trigger(q, false);
- else if (effectiveEnable)
+ if (wasEnabled && (!action || !action->isEnabled()))
emit q->clicked();
}