iOS: Fix a11y representation of RadioButton and CheckBox

RadioButton and CheckBox should not provide a value because this
leads to the behavior that iOS read out both states (checked and
unchecked). Also we need to provide own strings in multiple
languages because resolving 0 and 1 is not supported by iOS in
this case. This behavior is not intended by iOS. Instead we need
to provide the state with a UIAccessibilityTrait. This creates
the same representation as for the items in the iOS settings and
uses the iOS specific wording.

Task-number: QTBUG-139676
Pick-to: 6.9 6.8
Change-Id: I1369291cc9e8fbbe9ae65f2ca6c742d942d2acd6
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
(cherry picked from commit e9da800428)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Lars Schmertmann 2025-09-10 15:08:11 +02:00 committed by Qt Cherry-pick Bot
parent 7f78486717
commit 9db065a09e
1 changed files with 10 additions and 1 deletions

View File

@ -109,10 +109,15 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QMacAccessibilityElement);
QAccessible::State state = iface->state();
if (state.checkable)
if (state.checkable) {
if (iface->role() == QAccessible::CheckBox
|| iface->role() == QAccessible::RadioButton)
return @"";
return state.checked
? QCoreApplication::translate(ACCESSIBILITY_ELEMENT, AE_CHECKED).toNSString()
: QCoreApplication::translate(ACCESSIBILITY_ELEMENT, AE_UNCHECKED).toNSString();
}
QAccessibleValueInterface *val = iface->valueInterface();
if (val) {
@ -159,6 +164,10 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QMacAccessibilityElement);
const auto accessibleRole = iface->role();
if (accessibleRole == QAccessible::Button) {
traits |= UIAccessibilityTraitButton;
} else if (accessibleRole == QAccessible::CheckBox
|| accessibleRole == QAccessible::RadioButton) {
if (state.checked)
traits |= UIAccessibilityTraitSelected;
} else if (accessibleRole == QAccessible::EditableText) {
static auto defaultTextFieldTraits = []{
auto *textField = [[[UITextField alloc] initWithFrame:CGRectZero] autorelease];