-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.8.4, 6.9.2
-
None
Seen on iOS (18.6, 18.7): When selecting accessibility items in a QtQuick scene by tap, the item stacking isn't respected. In the following example, the button "Hello" is selected, although "World" is on top of it and should have precedence.
import QtQuick import QtQuick.Controls Window { width: 640 height: 480 visible: true title: qsTr("Hello World") Button { text: "Hello" anchors.centerIn: parent } Button { text: "World" anchors.centerIn: parent } }
With iOS 18 and later, accessibilityHitTest:withEvent has been added.
Adding this to quiview_accessibility.mm fixes the issue for me:
- (id)accessibilityHitTest:(CGPoint)point withEvent:(UIEvent *)event { if (!self.platformWindow) { return nil; } QWindow *win = self.platformWindow->window(); QAccessibleInterface *iface = win->accessibleRoot(); if (!iface) { return nil; } QPoint screenPoint = self.platformWindow->mapToGlobal(QPoint(point.x, point.y)); QAccessibleInterface *child = iface->childAt(screenPoint.x(), screenPoint.y()); if (!child) { return nil; } QAccessible::Id childId = QAccessible::uniqueId(child); // get existing native QMacAccessibilityElement - is there a better way? for (id object in m_accessibleElements) { if ([object isKindOfClass:[QMacAccessibilityElement class]] && ((QMacAccessibilityElement*)object).axid == childId) { return object; } }
As accessibilityHitTest:withEvent is new in iOS 18, I would assume it doesn't work in iOS 17 or older, but I couldn't confirm as I have no device to test available.
This interacts with QTBUG-138496, but is a separate issue, and is iOS only, while QTBUG-138496 affects both Android/iOS (and probably every platform where accessibility items are selected by tap). With this patch, one can also reproduce QTBUG-140394.
Note that the hit test would have to consider external windows in a solution that also fixes QTBUG-138406 . My patch fixing both can be found there. The patch checks whether the coordinates are in a subview, and if yes, calls the subviews default implementation of accessibilityHitTest:withEvent:.