Search code examples
qtscrollqlistview

Qt how to stop dragging viewport of QListView when using QScroller


I'm using QScroller on my QListView.

How can I stop dragging the list away when it reaches its beginning or its end?

Like image below. enter image description here


Solution

  • You have to set the overshoot policy of the QScrollerProperties. Here an example for the vertical scrolling:

    QScrollerProperties properties = QScroller::scroller(scrollWidget)->scrollerProperties();
    
    QVariant overshootPolicy = QVariant::fromValue<QScrollerProperties::OvershootPolicy>(QScrollerProperties::OvershootAlwaysOff);
    properties.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy, overshootPolicy);
    
    QScroller::scroller(scrollWidget)->setScrollerProperties(properties);