[PyQt] QTreeView (and QTreeWidget) horizontal scroll bar jumping

Doug Bell dougb at bellz.org
Tue Apr 8 03:04:39 BST 2014

Thomi Richards wrote:
> Hi,
> On 7 April 2014 14:21, Doug Bell <dougb at bellz.org> wrote:
> > I fixed this problem in my TreeLine program by overriding the
> > QTreeView::scrollTo method as shown below:
> >
> Thanks - that certainly fixes that problem.
> Now I'm trying to get it so that navigating (with the arrow keys) to items
> in the tree view that are either off to the RHS of the currently shown
> viewport, or off the bottom of the viewport causes the scroll bars to shift
> so the item is in view.
> I tried hooking the model's selectionChanged signal up to the new patched
> scrollTo method, but I'm pretty sure that's already called - in any case,
> it made no difference.
> Any ideas?

My guess is that you need to compare the horizontal coordinates of the
QTreeView::visualRect() for the item with the size of the
QAbstractScrollArea::viewport().  If the rectangle is not within the
viewport, change the horizPos in the scrollTo() function by a suitable


More information about the PyQt mailing list