Skip to content

Commit

Permalink
Avoided qt bug that QTreeView scroll incorrectly. (in scrollTo, Ensur…
Browse files Browse the repository at this point in the history
…eVisible).
  • Loading branch information
hidefuku committed Apr 10, 2017
1 parent 0f385aa commit 86b2e75
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/gui/ObjectTreeWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -913,4 +913,19 @@ void ObjectTreeWidget::resizeEvent(QResizeEvent* aEvent)
onScrollUpdated(scrollHeight());
}

void ObjectTreeWidget::scrollTo(const QModelIndex& aIndex, ScrollHint aHint)
{
// Avoided qt bug that QTreeView scroll incorrectly (in scrollTo, EnsureVisible).
if (aHint == ScrollHint::EnsureVisible)
{
auto view = this->viewport()->rect();
auto rect = this->visualRect(aIndex);
if (view.top() <= rect.top() && rect.bottom() <= view.bottom())
{
return; // nothing to do
}
}
QTreeWidget::scrollTo(aIndex, aHint);
}

} // namespace gui
1 change: 1 addition & 0 deletions src/gui/ObjectTreeWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class ObjectTreeWidget : public QTreeWidget
virtual void rowsInserted(const QModelIndex& aParent, int aStart, int aEnd);
virtual void scrollContentsBy(int aDx, int aDy);
virtual void resizeEvent(QResizeEvent* aEvent);
virtual void scrollTo(const QModelIndex& aIndex, ScrollHint aHint);

void createTree(core::ObjectTree* aTree);
void addItemRecursive(QTreeWidgetItem* aItem, core::ObjectNode* aNode);
Expand Down

0 comments on commit 86b2e75

Please sign in to comment.