PDA

View Full Version : Keeping focus at bottom of QListView



jakamph
9th January 2006, 22:08
I'm using QT 3.3.1 and have a main form that has a QListView that will continually have QListViewItems added to it with the top being the first one added and the bottom being the last one added. What I want to do is have the QListView stay at the bottom of the list. I've tried to use QListView::setCurrentItem on the last item, but that doesn't bring the QListView to the bottom, it just highlights the last QListViewItem. I've also tried to use QListView::ensureItemVisible, but after a few seconds, the refresh boggs down quite a bit to the point where the program essentially locks up. After taking a quick look at the code, it seems as though ::ensureItemVisible starts at the top and moves to the selected item and after getting a large number of items, this becomes horribly inefficient. Is there some sort of property that I can set that will cause the QListView to keep the scroll bar at the bottom of the list as things get added?

If there's any needed information that I've forgotten to provide, please feel free to ask.

Thanks in advance.

PS - I posted this over at the old board as well because I was having login trouble over here. Sorry for the double posting if you read this here and there.

jacek
9th January 2006, 22:20
QListView inherits QScrollView, so you might try QScrollView::scrollBy() or QScrollView::ensureVisible() together with QScrollView::contentsHeight ().

jakamph
10th January 2006, 14:59
QListView inherits QScrollView, so you might try QScrollView::scrollBy() or QScrollView::ensureVisible() together with QScrollView::contentsHeight ().

Using QScrollView::scrollBy( ) along with QScrollView::contentsHeight( ) seemed to work the best. However, it still boggs down around 9000 or so children. I just wish there was a property that I could set that could automatically keep the scroll bar at the bottom. Thanks for your help.

gadnio
10th January 2006, 15:02
another solution:
if ( list_view->lastChild() )
list_view->ensureItemVisible( list_view->lastChild() );

jakamph
10th January 2006, 15:45
another solution:
if ( list_view->lastChild() )
list_view->ensureItemVisible( list_view->lastChild() );

If you take a look at my initial post, I did try ::ensureItemVisible. However, that bogged down well before the 9000 children mark.