summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel/qwidget.cpp
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2024-04-08 14:13:09 +0200
committerMichael Weghorn <m.weghorn@posteo.de>2024-05-22 08:50:31 +0200
commit25ab8ada1019adf9e88addd47acb0924831edc5a (patch)
treec010536547001f4200bc8a52f26af95aeebbccc8 /src/widgets/kernel/qwidget.cpp
parent423ae2de96360619b5233ecb6a0be56b61ec58a3 (diff)
a11y: Notify of name change when setting window title used as a11y name
When no explicit accessible name is set for a window, QAccessibleWidget::text uses the window title instead for a non-minimized window. Send a QAccessible::NameChanged event when changing the window title results in a change of the accessible name, to ensure that the AT-SPI cache on Linux gets updated. Extend tst_QAccessibility::mainWindowTest() to cover the scenario as well. Note: The entire test function is skipped on platforms not supporting window activation, e.g. Wayland. Fixes: QTBUG-124192 Change-Id: I0fa7f683fb5969d6ba9878f6a506c4f192069799 Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'src/widgets/kernel/qwidget.cpp')
-rw-r--r--src/widgets/kernel/qwidget.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index ead633cda3e..750b2946766 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -6107,6 +6107,13 @@ void QWidget::setWindowTitle(const QString &title)
if (QWidget::windowTitle() == title && !title.isEmpty() && !title.isNull())
return;
+#if QT_CONFIG(accessibility)
+ QString oldAccessibleName;
+ const QAccessibleInterface *accessible = QAccessible::queryAccessibleInterface(this);
+ if (accessible)
+ oldAccessibleName = accessible->text(QAccessible::Name);
+#endif
+
Q_D(QWidget);
d->topData()->caption = title;
d->setWindowTitle_helper(title);
@@ -6115,6 +6122,13 @@ void QWidget::setWindowTitle(const QString &title)
QCoreApplication::sendEvent(this, &e);
emit windowTitleChanged(title);
+
+#if QT_CONFIG(accessibility)
+ if (accessible && accessible->text(QAccessible::Name) != oldAccessibleName) {
+ QAccessibleEvent event(this, QAccessible::NameChanged);
+ QAccessible::updateAccessibility(&event);
+ }
+#endif
}