Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. For ListView in QML when currentIndex is changed programatically onMovementStarted onMovementEnded are not called
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 4 Posters 2.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Amey
    wrote on last edited by Amey
    #1

    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

    1 Reply Last reply
    0
    • X Offline
      X Offline
      xargs1
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Amey
        wrote on last edited by
        #3

        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 ?

        1 Reply Last reply
        0
        • johngodJ Offline
          johngodJ Offline
          johngod
          wrote on last edited by johngod
          #4

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

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Amey
            wrote on last edited by
            #5

            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..

            p3c0P 1 Reply Last reply
            0
            • A Amey

              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..

              p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              @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.

              157

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved