Flickable - Scroll smoothly programatically

  • Hello,

    Imagine a Flickable item with 100 pixels height and 300 pixels contentHeight. If the user scrolls to down, the contentY property has 300. If the contentY is changed to 0, the Flickable item moves the content to the begin. But, how can I do a smooth scroll to up when the contentY is changed? The effect is like the user moves with its finger the content to the begin.

    Best regards.

  • @lqsa You can use the method flick to start an animated movement, see http://doc.qt.io/qt-5/qml-qtquick-flickable.html#flick-method

  • I've tested

    QMetaObject::invokeMethod(child, "flick", Q_ARG(qreal, 0.), Q_ARG(qreal, -200.)


    QMetaObject::invokeMethod(child, "flick", Q_ARG(qreal, 0.), Q_ARG(qreal, 200.)

    but nothing happens, doesn't scroll.

  • @lqsa In think you could use a Behavior on ContentY.

    Would this give you want ?

    import QtQuick 2.0
    import QtQuick.Window 2.0
        Flickable {
            width: 100; height: 150
            contentWidth: 300; contentHeight: 300
            Behavior on contentY{
                NumberAnimation {
                    duration: 1000
                    easing.type: Easing.OutBounce
                running: true;
                interval: 1500
                repeat: true
                    if (parent.contentY==0) parent.contentY=300;
                    else parent.contentY=0;
            Rectangle {
                width: 300; height: 300
                gradient: Gradient {
                    GradientStop { position: 0.0; color: "lightsteelblue" }
                    GradientStop { position: 1.0; color: "blue" }

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.