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. Transitioning to an item in ListView
Forum Updated to NodeBB v4.3 + New Features

Transitioning to an item in ListView

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 3 Posters 1.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.
  • ArasA Offline
    ArasA Offline
    Aras
    wrote on last edited by
    #1

    I am using a ListView to create a card layout so I can swipe left and right to switch from one page to another. However, there is a shortcut to go to "Home Page" which in my case is the card in the center. Lets say index 3. I can switch to this card using the following line:

            view.positionViewAtIndex(3, ListView.Beginning);
    

    Thats was nice and easy and is almost what I expected, however it is missing any sort of transitions. How can I switch to another item in the ListView and show some sort of transition to the user instead of instantly replacing the current item with the item at position?

    This is probably a very basic question for someone experienced with qml but I am a bit stuck as how to proceed. Thanks for your help in advance!

    J.HilkJ 1 Reply Last reply
    0
    • ArasA Aras

      I am using a ListView to create a card layout so I can swipe left and right to switch from one page to another. However, there is a shortcut to go to "Home Page" which in my case is the card in the center. Lets say index 3. I can switch to this card using the following line:

              view.positionViewAtIndex(3, ListView.Beginning);
      

      Thats was nice and easy and is almost what I expected, however it is missing any sort of transitions. How can I switch to another item in the ListView and show some sort of transition to the user instead of instantly replacing the current item with the item at position?

      This is probably a very basic question for someone experienced with qml but I am a bit stuck as how to proceed. Thanks for your help in advance!

      J.HilkJ Online
      J.HilkJ Online
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      Hi @Aras ,

      you could use something along this:

      ListView{
      ....
      ....
      property bool doAnimation: false
      
      Behavior  on contentY{
          enabled: doAnimation
          NumberAnimation{
              duration: 300
              onStopped: doAnimation = false
          }
      }
      ...
      }
      
      ...
      {
      doAnimation = true
      view.positionViewAtIndex(3, ListView.Beginning);
      }
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      2
      • ArasA Offline
        ArasA Offline
        Aras
        wrote on last edited by Aras
        #3

        Thanks for your response @J-Hilk
        I tried several variations of adding animation on contentX and contentY but I could not get it to work. positionViewAtIndex would switch to the correct index but without any transitions.

        I ended up using the following function:

                function gotoIndex(idx) {
        		var pos = view.contentY;
        		var destPos;
        		view.positionViewAtIndex(idx, ListView.Beginning);
        		destPos = view.contentY;
        		anim.from = pos;
        		anim.to = destPos;
        		anim.running = true;
        	}
        

        Which I found on this post: http://www.qtcentre.org/threads/40680-Animate-ListView-positionViewAtI

        That method worked very nicely. Thanks again for your help, it pointed me in the write direction.

        A 1 Reply Last reply
        2
        • ArasA Aras

          Thanks for your response @J-Hilk
          I tried several variations of adding animation on contentX and contentY but I could not get it to work. positionViewAtIndex would switch to the correct index but without any transitions.

          I ended up using the following function:

                  function gotoIndex(idx) {
          		var pos = view.contentY;
          		var destPos;
          		view.positionViewAtIndex(idx, ListView.Beginning);
          		destPos = view.contentY;
          		anim.from = pos;
          		anim.to = destPos;
          		anim.running = true;
          	}
          

          Which I found on this post: http://www.qtcentre.org/threads/40680-Animate-ListView-positionViewAtI

          That method worked very nicely. Thanks again for your help, it pointed me in the write direction.

          A Offline
          A Offline
          ambershark
          wrote on last edited by
          #4

          @Aras Don't forget to mark this as solved for future browsers of this forum. :)

          My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

          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