For ListView in QML when currentIndex is changed programatically onMovementStarted onMovementEnded are not called



  • For ListView in QML when currentIndex is changed programatically onMovementStarted onMovementEnded are not called

    Button
    {
    onClicked:
    myListView.currentIndex = 2; // Any number within bounds
    }
    ListView
    {
    id: myListView
    orientation: ListView.Horizontal
    onMovementStarted: { ...}
    onMovementEnded {. . .}
    }

    Now when the currentIndex is changed by button the OnMovementStarted() and OnMovementEnded OnFlickStarted, OnFlickEnded slots are not called.

    But when the user flickers with the touch screen the slots are called. how should I get the above slots called when done by button click?

    Thanks



  • The documentation says that those signals are emitted "due to user interaction", i.e., based on flicks or dragging, not by script.



  • Yes, but is there any other slot which would help me to know if Movement has ended when currentIndex has changed programmatically. I couldn't find any unfortunately. Can there be any workaround ?



  • Perhaps you can explain a little bit more of what you are trying to achieve, the big picture, so we can better help you ? Maybe there's another way of doing what you want without calling OnMovementStarted() by button click ? Perhaps bind a property to currentIndex and call onSomePropertyChanged()



  • Whenever the sliding of the listview happens OnMovementStart is called. This happens when the user slides on touchscreen.
    currentIndex changes when the movement has not yet stopped so binding to currentIndex is not helpful.

    I figured out a way to do this but is just a workaround..Not actually Qt provided slot, looks listview needs more properties to simulate this behaviour and required enhancements

    the workaround is....I know the animation duration time 500 ms or 1 sec before button click.
    So, I launch timer whenever the button is clicked and post process actions after OnTriggered is called

    Timer
    {
        repeat: false;
        running: false
        interval: 500
    
        onTriggered:
        {
            //perform post action
            running = false;
        }
    }
    

    This solves but makes this complex..


  • Moderators

    @Amey As @xargs1 pointed out those signals are only emitted on users interaction. Another workaround is to make use of contentY property and thus the onContentYChanged handler. It will be called in all cases. To detect if the movement has stopped you can put a condition to check current contentY with a pre-calculated value based on index and delegate's height.


Log in to reply
 

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