diff options
author | Tobias Hunger <tobias.hunger@qt.io> | 2017-11-21 15:36:44 +0100 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@qt.io> | 2017-11-22 08:41:45 +0000 |
commit | 7c96f0027ec9c72fbbc00b29637ad9d07474551c (patch) | |
tree | 168403946f011873b23b047c627b5a33e79d8b72 | |
parent | 983e2cd09d815c251c10e65fce9c4f26e11b051f (diff) |
NavigationTreeView: Improve horizontal scrolling in treeview
Do not move horizontally so often when scrolling to an index in the
TreeView. This is done by getting more accurate sizes for the items
being drawn.
Change-Id: I9cbc7912ede6a4bec3126c3ce9a0a4eb65805910
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
-rw-r--r-- | src/libs/utils/navigationtreeview.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/libs/utils/navigationtreeview.cpp b/src/libs/utils/navigationtreeview.cpp index 85490a9a17..143c294b35 100644 --- a/src/libs/utils/navigationtreeview.cpp +++ b/src/libs/utils/navigationtreeview.cpp @@ -25,8 +25,8 @@ #include "navigationtreeview.h" -#include <QHeaderView> #include <QFocusEvent> +#include <QHeaderView> #include <QScrollBar> /*! @@ -62,13 +62,18 @@ void NavigationTreeView::scrollTo(const QModelIndex &index, QAbstractItemView::S // work around QTBUG-3927 QScrollBar *hBar = horizontalScrollBar(); int scrollX = hBar->value(); + const int viewportWidth = viewport()->width(); - const QRect itemRect = visualRect(index); + QRect itemRect = visualRect(index); + + QAbstractItemDelegate *delegate = itemDelegate(index); + if (delegate) + itemRect.setWidth(delegate->sizeHint(viewOptions(), index).width()); + if (itemRect.x() - indentation() < 0) { // scroll so left edge minus one indent of item is visible scrollX += itemRect.x() - indentation(); - } else if (itemRect.right() > viewportWidth - && (viewportWidth - itemRect.x() < 3 * viewportWidth / 4)) { + } else if (itemRect.right() > viewportWidth) { // If right edge of item is not visible and left edge is "too far right", // then move so it is either fully visible, or to the left edge. // For this move the left edge one indent to the left, so the parent can potentially |