From 7c96f0027ec9c72fbbc00b29637ad9d07474551c Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Tue, 21 Nov 2017 15:36:44 +0100 Subject: [PATCH] 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 --- src/libs/utils/navigationtreeview.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/libs/utils/navigationtreeview.cpp b/src/libs/utils/navigationtreeview.cpp index 85490a9a17c..143c294b357 100644 --- a/src/libs/utils/navigationtreeview.cpp +++ b/src/libs/utils/navigationtreeview.cpp @@ -25,8 +25,8 @@ #include "navigationtreeview.h" -#include #include +#include #include /*! @@ -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