From 7782eeeefe381d47f8cc36d7154fd8152459da5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 5 May 2023 12:09:47 +0200 Subject: [PATCH] a11y: Don't add scrollbar container as a11y child if scroll bar is re-parented If someone has, for unknown reasons, re-parented the scroll bar of a scroll area to outside the scroll area, we should not blindly add the parent widget of the scroll bar as an a11y child of the scroll area. We don't need to explicitly add the scroll bar itself as a child either, as that will be handled by whoever is the new parent widget, as a normal scroll bar would. Fixes: QTBUG-93768 Change-Id: Ib26f31674602e2221311e864ad31bbf141cad8f6 Reviewed-by: Richard Moe Gustavsen (cherry picked from commit e51ff5c4935330b00d8039e435ec6cac60cfb875) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/accessible/complexwidgets.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/widgets/accessible/complexwidgets.cpp b/src/widgets/accessible/complexwidgets.cpp index df81713d721..4690a6e57fd 100644 --- a/src/widgets/accessible/complexwidgets.cpp +++ b/src/widgets/accessible/complexwidgets.cpp @@ -476,13 +476,19 @@ QWidgetList QAccessibleAbstractScrollArea::accessibleChildren() const // Horizontal scrollBar container. QScrollBar *horizontalScrollBar = abstractScrollArea()->horizontalScrollBar(); if (horizontalScrollBar && horizontalScrollBar->isVisible()) { - children.append(horizontalScrollBar->parentWidget()); + QWidget *scrollBarParent = horizontalScrollBar->parentWidget(); + // Add container only if scroll bar is in the container + if (elementType(scrollBarParent) == HorizontalContainer) + children.append(scrollBarParent); } // Vertical scrollBar container. QScrollBar *verticalScrollBar = abstractScrollArea()->verticalScrollBar(); if (verticalScrollBar && verticalScrollBar->isVisible()) { - children.append(verticalScrollBar->parentWidget()); + QWidget *scrollBarParent = verticalScrollBar->parentWidget(); + // Add container only if scroll bar is in the container + if (elementType(scrollBarParent) == VerticalContainer) + children.append(scrollBarParent); } // CornerWidget.