diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-04-18 22:05:36 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-04-22 06:44:31 +0000 |
commit | d204cebca48f753e2fc40e8d27e96905950c7ccb (patch) | |
tree | 129e187d617fb5c5eb2899ad9cddf2f1bf6ccd5e /tests | |
parent | 224eb8e3afc7cf3fde4f8b7d4610c078ee59e994 (diff) |
Accessibility: respect value in attached Accessible in controls
QQuickItemPrivate::accessibleRole is virtual and called by the framework
to determine the role of an item. The default implementation checks and
respects a possible Accessible attached object. However, subclasses that
override the virtual don't, so the attached properties are ignored, and
the class-specific implementation wins. This makes it impossible to
change the role of e.g. a checkable button.
To fix that, move the code respecting the attached object into a non-
virtual function that the framework calls instead, and only call the
virtual member if there is no attached object, or if that object is not
initialized with a role. Replace calls to the virtual from the
framework with calls to the non-virtual wrapper.
Do this for both QQuickItem and for QQuickPopup, and adjust the logic
in QQuickControl types that create an attached object and initialize
it's role when accessibility becomes active. Use the non-overridable
effective role value for that as well.
Add a test case, and to avoid any new framework calls to the virtual,
make it private.
Fixes: QTBUG-110114
Change-Id: Ia709cecbd181b6d8ee3297a4af60c1e7db9a2c51
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
(cherry picked from commit 3c08d08ae2bbd449cc0579a1b3cb499383c7a60c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qquickaccessible/tst_qquickaccessible.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickaccessible/tst_qquickaccessible.cpp b/tests/auto/quick/qquickaccessible/tst_qquickaccessible.cpp index e7da38a5ce..f51e7e8710 100644 --- a/tests/auto/quick/qquickaccessible/tst_qquickaccessible.cpp +++ b/tests/auto/quick/qquickaccessible/tst_qquickaccessible.cpp @@ -56,6 +56,7 @@ private slots: void commonTests(); void quickAttachedProperties(); + void attachedWins(); void basicPropertiesTest(); void hitTest(); void checkableTest(); @@ -322,6 +323,31 @@ void tst_QQuickAccessible::quickAttachedProperties() QTestAccessibility::clearEvents(); } +// Verify that a role can be explicitly set, and that the values from the +// attached object are used even if the item has a default role - QTBUG-110114 +void tst_QQuickAccessible::attachedWins() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.setData(R"( + import QtQuick + import QtQuick.Controls + Button { + text: "Button" + objectName: "button" + Accessible.role: Accessible.RadioButton + Accessible.description: "Radio Button" + })", QUrl()); + auto button = std::unique_ptr<QObject>(component.create()); + QVERIFY(button); + + QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(button.get()); + QVERIFY(iface); + + QCOMPARE(iface->role(), QAccessible::RadioButton); + QTestAccessibility::clearEvents(); +} + void tst_QQuickAccessible::basicPropertiesTest() { |