Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-137157

[macOS] QAccessibleInterface::window() is never called; accessibility tools cannot see the top-level window that holds a widget/Item

    XMLWordPrintable

Details

    • macOS
    • 5dc261357 (dev), c75046876 (6.10), 355d5b85a (6.9), ea9658e6c (tqtc/lts-6.8)

    Description

      Use-case: Grammarly queries the window information to display overlays on top of the app. It works fine on Windows but not macOS.

       

      TEST 1
      Code
      Qt Widgets version:

      #include <QtWidgets>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          QTextEdit te;
          te.setWindowTitle("Qt Widgets Window");
          te.show();
      
          return a.exec();
      }
      

       

      Qt Quick version:

      import QtQuick.Controls.Basic
      
      ApplicationWindow {
          width: 400
          height: 300
          visible: true
          title: "Qt Quick Window"
      
          TextArea { anchors.fill: parent }
      }
      

       

      Steps to reproduce

      Use Xcode's Accessibility Inspector to examine...

      1. ...the text input area of one of the Qt applications above
      2. ...the text input area of one of the native macOS TextEdit app

       

      Outcomes

      • (Step #1) Qt's "Text View" automation type has "None" as the value for its "Window" property (Not expected)
      • (Step #2) The macOS TextEdit's "Text View" automation type has a valid value for its "Window" property (Expected)

       

      TEST 2
      Code

      #include <QApplication>
      #include <QMainWindow>
      #include <QTextEdit>
      #include <QAccessibleWidget>
      
      class MyAccessibleWidget : public QAccessibleWidget
      {
      public:
          explicit MyAccessibleWidget(QWidget *w, const QString &name = "MyWidget")
              : QAccessibleWidget(w, QAccessible::EditableText, name)
          {}
      
          QString text(QAccessible::Text) const override
          {
              qDebug("MyAccessibleWidget::text() called");
              return QStringLiteral("Am I accessible?");
          }
      
          QWindow *window() const override
          {
              qDebug("MyAccessibleWidget::window() called");
              return QAccessibleWidget::window();
          }
      };
      
      static QAccessibleInterface *myFactoryFunction(const QString &, QObject *object)
      {
          auto te = qobject_cast<QTextEdit*>(object);
          return te ? new MyAccessibleWidget(te) : nullptr;
      }
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
          QAccessible::installFactory(&myFactoryFunction);
      
          QMainWindow mw;
          mw.setCentralWidget(new QTextEdit(&mw));
          mw.show();
      
          return app.exec();
      }
      

       

      Steps to reproduce

      1. Build and run the code above for both Windows and macOS
      2. Use the platform's accessibility checker to examine the QTextEdit of the example, while monitoring the qDebug output

       

      Outcomes

      • (Windows) The console output shows that both MyAccessibleWidget::text() and MyAccessibleWidget::window() are called many times (Expected)
      • (macOS) The console output shows that only MyAccessibleWidget::text() is called; MyAccessibleWidget::window() is never called (Not expected)

      Attachments

        For Gerrit Dashboard: QTBUG-137157
        # Subject Branch Project Status CR V

        Activity

          People

            vhilshei Volker Hilsheimer
            skoh-qt Sze Howe Koh
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There is 1 open Gerrit change