From 08c1f77c9a50bb8e1e5e37d7c428858022f4d400 Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Sat, 8 Jul 2023 15:16:12 +0200 Subject: [PATCH] a11y: Report app as parent for top-level item views As happens for other widgets (s. QAccessibleWidget::parentObject), report the app as accessible parent for item views that don't have another parent set. Otherwise, the accessible tree is broken when there's a top-level item view: The application has the item view as a child, but the child does not have any parent set. Extend a QListView autotest accordingly. Fixes: QTBUG-115135 Change-Id: Ie06874681180a30fc6248dc98f80c4158d837278 Reviewed-by: Volker Hilsheimer (cherry picked from commit 6ec35ff8c56222a317b838b6aac390eb6974de85) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/accessible/itemviews.cpp | 2 +- tests/auto/other/qaccessibility/tst_qaccessibility.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/widgets/accessible/itemviews.cpp b/src/widgets/accessible/itemviews.cpp index ae1de6cab4f..e640194a2ee 100644 --- a/src/widgets/accessible/itemviews.cpp +++ b/src/widgets/accessible/itemviews.cpp @@ -557,7 +557,7 @@ QAccessibleInterface *QAccessibleTable::parent() const } return QAccessible::queryAccessibleInterface(view()->parent()); } - return nullptr; + return QAccessible::queryAccessibleInterface(qApp); } QAccessibleInterface *QAccessibleTable::child(int logicalIndex) const diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp index bc19ca4470c..2fe8e0e5bd3 100644 --- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp @@ -2878,6 +2878,12 @@ void tst_QAccessibility::listTest() QCOMPARE(iface->indexOfChild(child3), 2); QCOMPARE(child3->text(QAccessible::Name), QString("Brisbane")); } + + // Check that application is accessible parent, since it's a top-level widget + QAccessibleInterface *parentIface = iface->parent(); + QVERIFY(parentIface); + QVERIFY(parentIface->role() == QAccessible::Application); + QTestAccessibility::clearEvents(); // Check for events