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

Thomi Richards thomir at gmail.com
Mon Apr 7 00:52:36 BST 2014


I have an application with a tree view that has a rather large tree inside
it. I've tweaked the tree view header so the tree view's horizontal
scrollbar works as I'd like, as documented here:


However, I notice that when I use the arrow keys to navigate a tree view,
every time I press the "Down" arrow on the keyboard to select a new tree
view item, the horizontal scrollbar resets itself to show the
left-hand-most content in the view.

I have a minimal example that shows the problem:


Run it, expand the tree with the arrow keys till it's off the right-hand
edge of the window. Move the scrollbar to the right, and try moving around
with the keyboard.

Ideally, the horizontal scrollbar would move left/right to keep the
currently selected item's text in view.

Does anyone know if this can be achieved? I imagine I'd need to override or
set something in QAbstractItemView, but the documentation for that class
seems rather opaque to me.


Thomi Richards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20140407/aa0eaba0/attachment-0001.html>

More information about the PyQt mailing list