diff options
author | Morten Johan Sørvig <morten.sorvig@qt.io> | 2021-05-07 10:07:50 +0200 |
---|---|---|
committer | Morten Johan Sørvig <morten.sorvig@qt.io> | 2021-06-01 10:46:34 +0200 |
commit | 41926e08d73ea6c4bbfc87a1dd52d2cdbc435c27 (patch) | |
tree | 4a4f2e747b51ef4268b023ac363c40883a889f7f /src/quickwidgets/qquickwidget.cpp | |
parent | 9586d32ec0ad126fc201697a691b1749387c3e33 (diff) |
Implement accessibility for QQuickWidget
The accessibility tree for the Qt Quick content should
be rooted at the QQuickWidget, and not at the offscreen
QQuickWindow.
For this to be the case, several things must happen:
- QQuickWindow must not report the child interfaces
- QQuickWidget must report the child interfaces
- The child interfaces must report the QQuickWidget as the parent
Create accessibility interfaces for QQuickWidget and
and QQuickWigetOffscreenWindow (which now gets a proper
subclass), where the QQuickWidget interface reports
the child interfaces and the QQuickWigetOffscreenWindow
reports no children
Change the code in QAccessibleQuickItem to use the
true (visible) window, where needed.
Fixes: QTBUG-67290
Change-Id: I387d0ef711138d248a8dd16eefc9839499b35eeb
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/quickwidgets/qquickwidget.cpp')
-rw-r--r-- | src/quickwidgets/qquickwidget.cpp | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp index 8ddd2d76c7..79e55fb78c 100644 --- a/src/quickwidgets/qquickwidget.cpp +++ b/src/quickwidgets/qquickwidget.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtQuick module of the Qt Toolkit. @@ -39,6 +39,7 @@ #include "qquickwidget.h" #include "qquickwidget_p.h" +#include "qaccessiblequickwidgetfactory_p.h" #include "private/qquickwindow_p.h" #include "private/qquickitem_p.h" @@ -84,9 +85,16 @@ QT_BEGIN_NAMESPACE +QQuickWidgetOffscreenWindow::QQuickWidgetOffscreenWindow(QQuickWindowPrivate &dd, QQuickRenderControl *control) +:QQuickWindow(dd, control) +{ + setTitle(QString::fromLatin1("Offscreen")); + setObjectName(QString::fromLatin1("QQuickWidgetOffscreenWindow")); +} + // override setVisble to prevent accidental offscreen window being created // by base class. -class QQuickOffcreenWindowPrivate: public QQuickWindowPrivate { +class QQuickWidgetOffscreenWindowPrivate: public QQuickWindowPrivate { public: void setVisible(bool visible) override { Q_Q(QWindow); @@ -112,14 +120,16 @@ private: void QQuickWidgetPrivate::initOffscreenWindow() { Q_Q(QQuickWidget); - offscreenWindow = new QQuickWindow(*new QQuickOffcreenWindowPrivate(), renderControl); - offscreenWindow->setTitle(QString::fromLatin1("Offscreen")); - offscreenWindow->setObjectName(QString::fromLatin1("QQuickOffScreenWindow")); + offscreenWindow = new QQuickWidgetOffscreenWindow(*new QQuickWidgetOffscreenWindowPrivate(), renderControl); // Do not call create() on offscreenWindow. QWidget::connect(offscreenWindow, SIGNAL(sceneGraphInitialized()), q, SLOT(createFramebufferObject())); QWidget::connect(offscreenWindow, SIGNAL(sceneGraphInvalidated()), q, SLOT(destroyFramebufferObject())); QWidget::connect(offscreenWindow, &QQuickWindow::focusObjectChanged, q, &QQuickWidget::propagateFocusObjectChanged); + +#if QT_CONFIG(accessibility) + QAccessible::installFactory(&qAccessibleQuickWidgetFactory); +#endif } void QQuickWidgetPrivate::init(QQmlEngine* e) @@ -1434,7 +1444,7 @@ void QQuickWidget::showEvent(QShowEvent *) if (shouldTriggerUpdate) triggerUpdate(); - // note offscreenWindow is "QQuickOffScreenWindow" instance + // note offscreenWindow is "QQuickWidgetOffscreenWindow" instance d->offscreenWindow->setVisible(true); if (QQmlInspectorService *service = QQmlDebugConnector::service<QQmlInspectorService>()) service->setParentWindow(d->offscreenWindow, window()->windowHandle()); @@ -1446,7 +1456,7 @@ void QQuickWidget::hideEvent(QHideEvent *) Q_D(QQuickWidget); if (!d->offscreenWindow->isPersistentSceneGraph()) d->invalidateRenderControl(); - // note offscreenWindow is "QQuickOffScreenWindow" instance + // note offscreenWindow is "QQuickWidgetOffscreenWindow" instance d->offscreenWindow->setVisible(false); if (QQmlInspectorService *service = QQmlDebugConnector::service<QQmlInspectorService>()) service->setParentWindow(d->offscreenWindow, d->offscreenWindow); |