From e51ff5c4935330b00d8039e435ec6cac60cfb875 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 Pick-to: 6.5 6.2 Change-Id: Ib26f31674602e2221311e864ad31bbf141cad8f6 Reviewed-by: Richard Moe Gustavsen --- 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 624090a2af..1248007417 100644 --- a/src/widgets/accessible/complexwidgets.cpp +++ b/src/widgets/accessible/complexwidgets.cpp @@ -477,13 +477,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.