summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel/qwidget.cpp
diff options
context:
space:
mode:
authorMichael Weghorn <[email protected]>2024-08-22 17:23:49 +0200
committerMichael Weghorn <[email protected]>2024-08-23 20:48:17 +0200
commit7fbe80c8a69c943198b48a9278fa6ef0e22b67de (patch)
tree2f0f48341271958dab1e15afdca7057e3374e25d /src/widgets/kernel/qwidget.cpp
parentfc2fa92de02e8b57472058a8281c24775e97d9eb (diff)
a11y: Notify of implicit window title change
Commit 25ab8ada1019adf9e88addd47acb0924831edc5a implemented sending a QAccessible::NameChanged event when the window name is used as accessible name and is changed by calling QWidget::setWindowTitle. Besides explicitly setting a new window title that way, the title can also be changed less explicitly: If the window title contains a corresponding "[*]" placeholder, changing the QWidget::windowModified property also results in a changed window title, with no QAccessible::NameChanged being sent so far. Move the logic introduced in 25ab8ada1019adf9e88addd47acb0924831edc5a further down into QWidgetPrivate::setWindowTitle_sys so it covers that case as well. While at it, also adjust this to skip retrieving the accessible here after all if accessibility is not enabled. This also needs 5178606a98be57f6dc5f3dddc1fa0f1e16c933e5 (for xcb; corresponding qtwayland still pending in Gerrit) for the event to actually be sent for the QWidget::setWindowModified case, because oldAccessibleName in QWidgetPrivate::setWindowTitle_sys would previously already be evaluated to the new accessible name by qt_setWindowTitle_helperHelper instead of using the old window title still set on the window before the actual title gets updated. Fixes: QTBUG-128296 Change-Id: Iaf80cd4019b6bc7383f425b45ece51f322a9e1c4 Reviewed-by: Volker Hilsheimer <[email protected]>
Diffstat (limited to 'src/widgets/kernel/qwidget.cpp')
-rw-r--r--src/widgets/kernel/qwidget.cpp31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index 32ac298ac8e..8b9513e2dd3 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -6057,8 +6057,25 @@ void QWidgetPrivate::setWindowTitle_sys(const QString &caption)
return;
if (QWindow *window = q->windowHandle())
+ {
+#if QT_CONFIG(accessibility)
+ QString oldAccessibleName;
+ const QAccessibleInterface *accessible = QAccessible::isActive()
+ ? QAccessible::queryAccessibleInterface(q)
+ : nullptr;
+ if (accessible)
+ oldAccessibleName = accessible->text(QAccessible::Name);
+#endif
+
window->setTitle(caption);
+#if QT_CONFIG(accessibility)
+ if (accessible && accessible->text(QAccessible::Name) != oldAccessibleName) {
+ QAccessibleEvent event(q, QAccessible::NameChanged);
+ QAccessible::updateAccessibility(&event);
+ }
+#endif
+ }
}
void QWidgetPrivate::setWindowIconText_helper(const QString &title)
@@ -6124,13 +6141,6 @@ 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);
@@ -6139,13 +6149,6 @@ 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
}