Search code examples
qtqml

QML ScrollBar: what is the purpose of stepSize property?


stepSize property

I've tried to initialize this property with different values, but got no visible effect when I scroll my ListView control.


Solution

  • In the following ListView, I created 100 records with model: 100 and you will see that stepSize: 0.25 causes the ListView to stop at 0, 25, 50, 75 and 99 spots respectively. It requires snapMode: ScrollBar.SnapOnRelease to be set

        ListView {
            width: 150
            height: 300
            model: 100
            delegate: Frame { ItemDelegate { text: modelData } }
            ScrollBar.vertical: ScrollBar {
                id: vbar
                width: 20
                policy: ScrollBar.AlwaysOn
                snapMode: ScrollBar.SnapOnRelease
                stepSize: 0.25
            }
            WheelHandler {
                onWheel: Qt.callLater(event.angleDelta.y > 0 ? vbar.decrease : vbar.increase)
            }
        }
    

    You can Try it online!