[Interest] QAccessible::InterfaceType is wrong when used with the NVDA screen reader

Nikos Chantziaras realnc at gmail.com
Mon Jul 3 18:50:02 CEST 2017


Hello.

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. 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, and it works 
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?




More information about the Interest mailing list