Reputation: 51890
I'm on Qt 5.9.1.
I'm trying to make an application accessible through screen readers. I have a custom widget (let's call it MyWidget
) that contains text (a lot of it.) The text is drawn using QPainter
, which is why a custom widget is used rather than something like QTextBrowser
.
I implemented the QAccessibleTextInterface
for the widget in a AccessibleMyWidget
class that derives from QAccessibleWidget
and QAccessibleTextInterface
. It works fine with Orca under Linux, but when used in Windows 7 with NVDA, QAccessibleInterface::interface_cast()
requests the wrong interface type. With Orca, I get requests for a QAccessible::TextInterface
. In NVDA, it's always QAccessible::ValueInterface
.
AccessibleMyWidget
is defined as:
class AccessibleMyWidget:
public QAccessibleWidget, public QAccessibleTextInterface {
public:
explicit AccessibleMyWidget(QWidget* w)
: QAccessibleWidget(w, QAccessible::EditableText)
{
Q_ASSERT(isValid());
}
void* interface_cast(QAccessible::InterfaceType t) override
{
if (t == QAccessible::TextInterface) {
// !!! This is never requested with NVDA !!!
return static_cast<QAccessibleTextInterface*>(this);
}
return QAccessibleWidget::interface_cast(t);
}
/*
* QAccessibleTextInterface implementation below this point.
*/
void addSelection(int startOffset, int endOffset) override;
QString attributes(int offset, int* startOffset,
int* endOffset) const override;
// etc.
};
With Orca under Linux, everything seems to work as intended. I get calls to interface_cast()
for a TextInterface
, and after that, the various functions of QAccessibleTextInterface
are called. With NVDA under Linux, I just get interface_cast()
calls for ValueInterface
, and none of the QAccessibleTextInterface
functions are called. Which means MyWidget
is completely inaccessible, unless I override QAccessibleWidget::text()
and just return all text as a single string, which means no cursor navigation, no selection support... It basically becomes just a QLabel
at this point, but with a ton of text and thus very hard to use.
What am I missing here?
Upvotes: 1
Views: 202
Reputation: 51890
Well, an NVDA developer helped me track down the issue. It's because the MinGW version of Qt has IAccessible2 disabled and uses MSAA (Microsoft Active Accessibility) instead, which doesn't support any of these interfaces. IA2 needs COM, and MinGW doesn't support that.
So I would have to switch from GCC/MinGW to MSVC to make this work on Windows. Too bad that's not actually an option in the foreseeable future :-/
2020 update:
This has been fixed since. Not sure when exactly, but the current mingw Qt builds now support this.
Upvotes: 1