Important: Please read the Qt Code of Conduct -

Calling QML Listview signal handler explicitly from QML

  • I am using Listview(id : listview) in my application. I want to move the listview with up/down arrow buttons as well. So I created up/down buttons with in application to do the movement. When up/down button clicked, I am calling listview.onMovementStarted() and re positioning the listview by changing the contentY. Now the issue is when Listview is moved by flicking on the listview and then arrows are clicked immediately. So firstly onMovementStarted got called and then as listview.onMovementStarted() is called onMovementStarted got called again. Then onmovementEnded() has called though listview is still moving. Can somebody tell how to solve this or it is expected to behave like this?

    Is it proper way to call listview.onMovementStarted() or listview.onMovementEnded() explicitly?

    Thanks in advance for your reply.

  • @Yaswanth
    You don't call another object's signal handler directly. If you want to send it a signal, you invoke the signal as a method, in this case
    listview.movementStarted(). But you don't want to do that either. You can call the flick() method or animate the contentY property.

    If you want to prevent the listview from getting flicked while moving, just check the moving or flicking properties in onMovementStarted() and call cancelFlick().

  • @Tom_H Thanks for your reply. Is it recommend way to invoke Signal as a method? Because I didn't find any info in the documentation.

  • @Yaswanth
    It's in The QML Reference, under QML Object Attributes.

    "To emit a signal, invoke it as a method. Any relevant signal handlers will be invoked when the signal is emitted, and handlers can use the defined signal argument names to access the respective arguments."

  • @Tom_H Thanks for your response. I have invoked the Listview signal as a method. But still the problem is same. Signal sequence is as following

    1. listview.onMovementStarted()
    2. listview.onMovementStarted()
    3. listview.onMovementEnded()

  • @Yaswanth
    You don't want to invoke the signal. Please read my first reply again.

  • @Tom_H Due to other constraints I can not use flick, so I have to go by signal invoking only.

  • Qt Champions 2018

    @Yaswanth Why not use a custom function then ? Calling movementStarted makes no sense.

  • @Yaswanth
    You can also prevent unwanted flicking by disabling the buttons when the view is moving.

    button.enabled:  !listview.moving

Log in to reply