forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -25,8 +25,8 @@
|
|||||||
|
|
||||||
#include "navigationtreeview.h"
|
#include "navigationtreeview.h"
|
||||||
|
|
||||||
#include <QHeaderView>
|
|
||||||
#include <QFocusEvent>
|
#include <QFocusEvent>
|
||||||
|
#include <QHeaderView>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -62,13 +62,18 @@ void NavigationTreeView::scrollTo(const QModelIndex &index, QAbstractItemView::S
|
|||||||
// work around QTBUG-3927
|
// work around QTBUG-3927
|
||||||
QScrollBar *hBar = horizontalScrollBar();
|
QScrollBar *hBar = horizontalScrollBar();
|
||||||
int scrollX = hBar->value();
|
int scrollX = hBar->value();
|
||||||
|
|
||||||
const int viewportWidth = viewport()->width();
|
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) {
|
if (itemRect.x() - indentation() < 0) {
|
||||||
// scroll so left edge minus one indent of item is visible
|
// scroll so left edge minus one indent of item is visible
|
||||||
scrollX += itemRect.x() - indentation();
|
scrollX += itemRect.x() - indentation();
|
||||||
} else if (itemRect.right() > viewportWidth
|
} else if (itemRect.right() > viewportWidth) {
|
||||||
&& (viewportWidth - itemRect.x() < 3 * viewportWidth / 4)) {
|
|
||||||
// If right edge of item is not visible and left edge is "too far right",
|
// 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.
|
// 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
|
// For this move the left edge one indent to the left, so the parent can potentially
|
||||||
|
Reference in New Issue
Block a user