tags:

views:

491

answers:

2

I have a QListView in Icon mode with lots of icons, so that a scrollbar appears, but the scrolling is not smooth and this IMHO confuses the user since it jumps abruptly from one point to another at each scroll. I would like to make the scrolling smooth but I didn't find anything in the docs. Is it possible?

+1  A: 

Maybe QListView.setVerticalScrollMode(QAbstractItemView::ScrollPerPixel)

Gary van der Merwe
It seems like the correct property but it didn't work. It scrolls just like before.
Massimiliano Torromeo
+1  A: 

If I understand your question correctly you would like to redefine the scrolling behavior of the widget. I guess what happens is that listview is getting scrolled by the item's height whenever users hits a scroll arrow (marked as b on the image below).

alt text

For a vertical scroll bar connected to a list view, scroll arrows typically move the current position one "line" up or down, and adjust the position of the slider by a small amount. I believe line in this case it is an icon's height. You can adjust items height by installing and item delegate (setItemDelegate) and overriding its sizeHint method. Though this would not help you to solve this problem. What you could try is to create a QListView descendant and override its updateGeometries method. There you can setup the vertical scrollbar step to the value you want, I guess 1 or 2 for this task. Below is an example of the custom listview:

class TestListView : public QListView
{
Q_OBJECT
public:
    explicit TestListView(QWidget *parent = 0);

protected:
    virtual void updateGeometries();
};

TestListView::TestListView(QWidget *parent) :
    QListView(parent)
{
    //???
}

void TestListView::updateGeometries()
{
    QListView::updateGeometries();
    verticalScrollBar()->setSingleStep(2);
}

hope this helps, regards

serge_gubenko
Interesting. I will try this soon. Thanks!
Massimiliano Torromeo
It worked perfectly, thanks!
Massimiliano Torromeo