summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel/qwidget.cpp
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2022-06-15 12:32:23 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-06-16 22:39:26 +0000
commitef75047a6330b592ce14c7ff8d9b75ad11dc2460 (patch)
tree669fa27152572e281ff0714aafdedde62195c3d8 /src/widgets/kernel/qwidget.cpp
parentbbde24f19a3704603f7a3f37e75fd5b7f881ee73 (diff)
Accessibility: don't emit focus change when reason is window activation
If a window becomes active, then the accessibility system gets informed about that already. Qt puts focus on the focus child of the activated window afterwards, and if this emits another accessibility event, then accessibility clients like Windows Narrator will stop reading the activated window, and instead read about the focused widget. This makes dialogs like message boxes poorly accessible. Accessibility clients already know that a window became active, and can query Qt about the focused child within that window. Amend test case. Fixes: QTBUG-101585 Change-Id: I2d6bff7c415a6f29c4a4f7f4e4be38079fb976ca Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io> (cherry picked from commit 79a11470f3c4c61951906223f97001a77ce36500) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/widgets/kernel/qwidget.cpp')
-rw-r--r--src/widgets/kernel/qwidget.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index ebbb2dffb8..cf32ff6c93 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -6513,11 +6513,15 @@ void QWidget::setFocus(Qt::FocusReason reason)
QApplicationPrivate::setFocusWidget(f, reason);
#if QT_CONFIG(accessibility)
- // menus update the focus manually and this would create bogus events
- if (!(f->inherits("QMenuBar") || f->inherits("QMenu") || f->inherits("QMenuItem")))
- {
- QAccessibleEvent event(f, QAccessible::Focus);
- QAccessible::updateAccessibility(&event);
+ // If the widget gets focus because its window becomes active, then the accessibility
+ // subsystem is already informed about the window opening, and also knows which child
+ // within the window has focus. Don't interrupt it by emitting another focus event.
+ if (reason != Qt::ActiveWindowFocusReason) {
+ // menus update the focus manually and this would create bogus events
+ if (!(f->inherits("QMenuBar") || f->inherits("QMenu") || f->inherits("QMenuItem"))) {
+ QAccessibleEvent event(f, QAccessible::Focus);
+ QAccessible::updateAccessibility(&event);
+ }
}
#endif
#if QT_CONFIG(graphicsview)