PDA

View Full Version : QListView with conditional vertical automatic scroll



jmesquita
30th July 2009, 04:15
I am trying to achieve a console like behaviour to a QListView where everytime the vertical scroll bar is set all the way to the bottom and a new item is added, scroll it so that the new item is visible.

I came up with this piece of code put where every new item is added:


if (QListView::verticalScrollBar()->value() == QListView::verticalScrollBar()->sliderPosition())
{
QListView::scrollToBottom();
}

Problem is, even tho tracking is enabled on the QAbstractScrollBar widget, I always get value() and sliderPosition() with the same value making the QListView always scroll down.

Is this the best way out of this? If not, what should be my solution? If it is, what am I missing that make those 2 values identical no matter what?

navi1084
30th July 2009, 04:36
you can accomplish last added item/row to be visible and scroll down automatically using the API

setCurrentCell(row, colum)

jmesquita
1st August 2009, 03:09
Well, two problems there.

1. setCurrentCell is a QTableWidget method, not a QListView method.
2. Even tho there is an equivalent method for QListView, this does not solve the question at hand since the problem is not how to scroll the new item but how to check if the vertical scrollbar is rolled all the way to the bottom.

This is still unsolved and I can't figure out why the condition as described on the first post always returns true.

Regards,

Mesquita