diff options
author | André de la Rocha <andre.rocha@qt.io> | 2022-03-25 02:14:12 -0300 |
---|---|---|
committer | André de la Rocha <andre.rocha@qt.io> | 2022-03-31 09:04:09 -0300 |
commit | 4114a0ea758d7f808011f9db0524c541880c16ed (patch) | |
tree | 29288604a2389b50c5f90902b24d37a5651cbeea /src/widgets/accessible | |
parent | 350a75f792156724a620ddfb987c27cfd767abbf (diff) |
Windows QPA: Fix slowdown with large table/tree views with accessibility
The accessibility code for notifying focus changes related to a
table/tree view was iterating over all items to find the focused one,
which for a very large number of items could cause a major slowdown
and UI freeze. This patch avoids the issue by removing the loop and
implementing the focusChild() method in the table/tree accessibility
classes.
Fixes: QTBUG-100997
Pick-to: 6.2 6.3 5.15
Change-Id: I04c847a5e65223b7a93ab82363feb32e1ebab9f3
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets/accessible')
-rw-r--r-- | src/widgets/accessible/itemviews.cpp | 23 | ||||
-rw-r--r-- | src/widgets/accessible/itemviews_p.h | 2 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/widgets/accessible/itemviews.cpp b/src/widgets/accessible/itemviews.cpp index a7b536ae54..e485744dc8 100644 --- a/src/widgets/accessible/itemviews.cpp +++ b/src/widgets/accessible/itemviews.cpp @@ -425,6 +425,15 @@ QAccessibleInterface *QAccessibleTable::childAt(int x, int y) const return nullptr; } +QAccessibleInterface *QAccessibleTable::focusChild() const +{ + QModelIndex index = view()->currentIndex(); + if (!index.isValid()) + return nullptr; + + return child(logicalIndex(index)); +} + int QAccessibleTable::childCount() const { if (!view()->model()) @@ -692,6 +701,20 @@ QAccessibleInterface *QAccessibleTree::childAt(int x, int y) const return child(i); } +QAccessibleInterface *QAccessibleTree::focusChild() const +{ + QModelIndex index = view()->currentIndex(); + if (!index.isValid()) + return nullptr; + + const QTreeView *treeView = qobject_cast<const QTreeView*>(view()); + int row = treeView->d_func()->viewIndex(index) + (horizontalHeader() ? 1 : 0); + int column = index.column(); + + int i = row * view()->model()->columnCount() + column; + return child(i); +} + int QAccessibleTree::childCount() const { const QTreeView *treeView = qobject_cast<const QTreeView*>(view()); diff --git a/src/widgets/accessible/itemviews_p.h b/src/widgets/accessible/itemviews_p.h index 683ae9c948..1fc6a3e521 100644 --- a/src/widgets/accessible/itemviews_p.h +++ b/src/widgets/accessible/itemviews_p.h @@ -79,6 +79,7 @@ public: QRect rect() const override; QAccessibleInterface *childAt(int x, int y) const override; + QAccessibleInterface *focusChild() const override; int childCount() const override; int indexOfChild(const QAccessibleInterface *) const override; @@ -154,6 +155,7 @@ public: QAccessibleInterface *childAt(int x, int y) const override; + QAccessibleInterface *focusChild() const override; int childCount() const override; QAccessibleInterface *child(int index) const override; |