Mike Shaw
Mike Shaw

Reputation: 393

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

Upvotes: 5

Views: 1585

Answers (1)

tomvodi
tomvodi

Reputation: 5897

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); 

Upvotes: 8

Related Questions