How to add the UIA ExpandCollapse pattern in Qml

99 views Asked by At

I'm using http://accessibilityinsights.io/ to make sure my QML application passes Microsoft requirements for accessibility.

There's only one error that I couldn't resolve.

Qml ComboBoxes don't have the ExpandCollapse pattern.

Code to reproduce:

ComboBox {
    model: ["First", "Second", "Third"]
}

Accessibility Insights says "An element of the given ControlType must support the ExpandCollapse pattern. Section 508 502.3.10

And "How to fix": 1. Make sure the element has the appropriate ControlType property for its function. 2. If the current ControlType is correct, modify the element to support the ExpandCollapse pattern.

StackOverflow couldn't help me. Google couldn't help me (I tried looking everywhere...)

So I went to Qt's source code.

I found this: qt-everywhere-src-6.2.1\qtbase\src\plugins\platforms\windows\uiautomation\qwindowsuiamainprovider.cpp

And here's the part that was interesting:

case UIA_ExpandCollapsePatternId:
// Menu items with submenus.
if (accessible->role() == QAccessible::MenuItem
        && accessible->childCount() > 0
        && accessible->child(0)->role() == QAccessible::PopupMenu) {
    *pRetVal = new QWindowsUiaExpandCollapseProvider(id());
}

Which means that there must be a MenuItem object (the qml combobox doesn't have that), nor a child that's a PopupMenu.

So I checked, and the ExpandCollapse pattern works fine in a menu (from QWidgets), but not in qml.

I couldn't change the combobox's role (Accessible.MenuItem), it doesn't register for some reason (perhaps because of the c++ backend)

I tried "hacking" this in qml, to see if it could work, with this:

MenuItem
{
    text: "test"
    Rectangle {
        Accessible.role: Accessible.PopupMenu
        visible:false // to make the state "collapsed" by default.
    }
}

And ... it works. I have the pattern. But obviously this isn't a combobox (not by name, not for accessibility, and not for functionality).

So here's my question: is there a way to maybe have my custom combobox to have the combobox Accessible.role, while having this structure (Accessible.MenuItem + Accessible.PopupMenu) to make qwindowsuiamainprovider.cpp add the ExpandCollapse pattern?

Or is the only way to find a way to either change qwindowsuiamainprovider.cpp, or override it or something?

I couldn't find any way to change it without recompiling Qt myself with this change (I would also have to check the license if I'm allowed to do it...)

0

There are 0 answers