aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2019-02-01 16:03:56 +0100
committerMitch Curtis <mitch.curtis@qt.io>2019-02-28 11:14:05 +0000
commit05eb8127594f0d40247e8c84a4704277dd12d16e (patch)
treeacdf630aef450d658ac894653f77ba70af98c921 /src
parent637630cc7ed0e6efd43678b11d1309e72a957874 (diff)
QQuickMenu: allow enter/return to be used to activate items
Before this patch, only space was allowed. Windows 10 and macOS 10.14.2 both allow using enter to activate menu items. Change-Id: I64476347669ff73f233efd129563a18ba51618a5 Fixes: QTBUG-73354 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/quicktemplates2/qquickabstractbutton.cpp9
-rw-r--r--src/quicktemplates2/qquickabstractbutton_p_p.h2
-rw-r--r--src/quicktemplates2/qquickmenuitem.cpp5
-rw-r--r--src/quicktemplates2/qquickmenuitem_p_p.h2
4 files changed, 16 insertions, 2 deletions
diff --git a/src/quicktemplates2/qquickabstractbutton.cpp b/src/quicktemplates2/qquickabstractbutton.cpp
index 3b41f34c..c2df6dc2 100644
--- a/src/quicktemplates2/qquickabstractbutton.cpp
+++ b/src/quicktemplates2/qquickabstractbutton.cpp
@@ -201,6 +201,11 @@ void QQuickAbstractButtonPrivate::handleUngrab()
emit q->canceled();
}
+bool QQuickAbstractButtonPrivate::acceptKeyClick(Qt::Key key) const
+{
+ return key == Qt::Key_Space;
+}
+
bool QQuickAbstractButtonPrivate::isPressAndHoldConnected()
{
Q_Q(QQuickAbstractButton);
@@ -1029,7 +1034,7 @@ void QQuickAbstractButton::keyPressEvent(QKeyEvent *event)
{
Q_D(QQuickAbstractButton);
QQuickControl::keyPressEvent(event);
- if (event->key() == Qt::Key_Space) {
+ if (d->acceptKeyClick(static_cast<Qt::Key>(event->key()))) {
d->setPressPoint(QPoint(qRound(width() / 2), qRound(height() / 2)));
setPressed(true);
@@ -1045,7 +1050,7 @@ void QQuickAbstractButton::keyReleaseEvent(QKeyEvent *event)
{
Q_D(QQuickAbstractButton);
QQuickControl::keyReleaseEvent(event);
- if (event->key() == Qt::Key_Space) {
+ if (d->acceptKeyClick(static_cast<Qt::Key>(event->key()))) {
setPressed(false);
nextCheckState();
diff --git a/src/quicktemplates2/qquickabstractbutton_p_p.h b/src/quicktemplates2/qquickabstractbutton_p_p.h
index 718498a8..7394f115 100644
--- a/src/quicktemplates2/qquickabstractbutton_p_p.h
+++ b/src/quicktemplates2/qquickabstractbutton_p_p.h
@@ -75,6 +75,8 @@ public:
void handleRelease(const QPointF &point) override;
void handleUngrab() override;
+ virtual bool acceptKeyClick(Qt::Key key) const;
+
bool isPressAndHoldConnected();
void startPressAndHold();
void stopPressAndHold();
diff --git a/src/quicktemplates2/qquickmenuitem.cpp b/src/quicktemplates2/qquickmenuitem.cpp
index b02b8e60..22fe664a 100644
--- a/src/quicktemplates2/qquickmenuitem.cpp
+++ b/src/quicktemplates2/qquickmenuitem.cpp
@@ -147,6 +147,11 @@ void QQuickMenuItemPrivate::executeArrow(bool complete)
quickCompleteDeferred(q, arrowName(), arrow);
}
+bool QQuickMenuItemPrivate::acceptKeyClick(Qt::Key key) const
+{
+ return key == Qt::Key_Space || key == Qt::Key_Return || key == Qt::Key_Enter;
+}
+
/*!
\qmlsignal void QtQuick.Controls::MenuItem::triggered()
diff --git a/src/quicktemplates2/qquickmenuitem_p_p.h b/src/quicktemplates2/qquickmenuitem_p_p.h
index 034a199a..58a0ff20 100644
--- a/src/quicktemplates2/qquickmenuitem_p_p.h
+++ b/src/quicktemplates2/qquickmenuitem_p_p.h
@@ -73,6 +73,8 @@ public:
void cancelArrow();
void executeArrow(bool complete = false);
+ bool acceptKeyClick(Qt::Key key) const override;
+
bool highlighted = false;
QQuickDeferredPointer<QQuickItem> arrow;
QQuickMenu *menu = nullptr;