aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2025-06-17 11:20:51 +0200
committerMichael Weghorn <m.weghorn@posteo.de>2025-07-01 07:36:34 +0200
commit216854a7f32dccf9666c16503026e0c554fd14f9 (patch)
treec030ca0081ff54a81198b1ddf0e5403f477fcc1f /src
parent78e8c91afa1e5003dfad0bc864d70cf5389e6888 (diff)
QQuickAbstractButton a11y: Strip mnemonic for accessible name
When setting the accessible name for a QQuickAbstractButton, don't include the ampersand ('&') character that denotes the mnemonic character, and don't escape literal ampersand characters by doubling them. Use the same helper function also used by widgets in qtbase to strip those extra ampersand characters. Add a corresponding test. Fixes: QTBUG-134208 Pick-to: 6.8 6.5 Change-Id: I0da58564ef028cda3c1cc1cecbaacbb4e9d92c17 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit db2792dd8609ab5ff4f3151e15036de7ffd538e9) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit a8b03139eb207741d13af91122e9e5b80dd813ec)
Diffstat (limited to 'src')
-rw-r--r--src/quicktemplates/qquickabstractbutton.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/quicktemplates/qquickabstractbutton.cpp b/src/quicktemplates/qquickabstractbutton.cpp
index a7e1a1275d..3f2087d7d0 100644
--- a/src/quicktemplates/qquickabstractbutton.cpp
+++ b/src/quicktemplates/qquickabstractbutton.cpp
@@ -15,6 +15,9 @@
#if QT_CONFIG(shortcut)
# include <QtGui/private/qshortcutmap_p.h>
#endif
+#if QT_CONFIG(accessibility)
+#include <QtGui/private/qaccessiblehelper_p.h>
+#endif
#include <QtGui/private/qguiapplication_p.h>
#include <QtGui/qpa/qplatformtheme.h>
#include <QtQuick/private/qquickevents_p_p.h>
@@ -1286,7 +1289,9 @@ void QQuickAbstractButton::buttonChange(ButtonChange change)
break;
case ButtonTextChange: {
const QString txt = text();
- maybeSetAccessibleName(txt);
+#if QT_CONFIG(accessibility)
+ maybeSetAccessibleName(qt_accStripAmp(txt));
+#endif
#if QT_CONFIG(shortcut)
setShortcut(QKeySequence::mnemonic(txt));
#endif
@@ -1325,7 +1330,7 @@ void QQuickAbstractButton::accessibilityActiveChanged(bool active)
Q_D(QQuickAbstractButton);
if (active) {
- maybeSetAccessibleName(text());
+ maybeSetAccessibleName(qt_accStripAmp(text()));
setAccessibleProperty("pressed", d->pressed);
setAccessibleProperty("checked", d->checked);
setAccessibleProperty("checkable", d->checkable);