Results 1 to 4 of 4

Thread: Animate ListView positionViewAtIndex

  1. #1
    Join Date
    Mar 2010
    Location
    Capelle aan den IJssel, Netherlands
    Posts
    24
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Question Animate ListView positionViewAtIndex

    Hello all,

    I want to create a ListView with some items. I have no problems there.
    Just now, when an item is added, that does not fit in the list anymore, I would like the list to add the item and then scroll up.

    I now implemented this with positionViewAtIndex, which works. But this is an immediate action. I want the list to visually scroll up, or maybe even better, animate the adding of the item (which is animated on height, so goes from 0 height, to 70) and scroll up at the same time, or something.

    Anyway, something more fancy than I have now =)
    I cannot find anything on the internet how to do this.

    Maybe someone has done this before, or can point me in the right direction?

  2. #2
    Join Date
    Apr 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Animate ListView positionViewAtIndex

    I'm advised with this from the qt support (though I don't get some details in this implementation):
    Qt Code:
    1. import QtQuick 1.0
    2.  
    3. Rectangle {
    4. id: window
    5. width: 360
    6. height: 640
    7.  
    8. function gotoIndex(idx) {
    9. var pos = view.contentY;
    10. var destPos;
    11. view.positionViewAtIndex(idx, ListView.Beginning);
    12. destPos = view.contentY;
    13. anim.from = pos;
    14. anim.to = destPos;
    15. anim.running = true;
    16. }
    17.  
    18. GridView{
    19. id: view
    20. anchors.fill: parent
    21. model: 200
    22. delegate: Text { text: index }
    23. }
    24.  
    25. MouseArea {
    26. anchors.fill: parent
    27. onClicked: gotoIndex(30)
    28. }
    29.  
    30. NumberAnimation { id: anim; target: view; property: "contentY"; duration: 500 }
    31. }
    To copy to clipboard, switch view to plain text mode 

  3. #3

    Default Re: Animate ListView positionViewAtIndex

    Quote Originally Posted by leonty View Post
    I'm advised with this from the qt support (though I don't get some details in this implementation):
    Qt Code:
    1. import QtQuick 1.0
    2.  
    3. Rectangle {
    4. id: window
    5. width: 360
    6. height: 640
    7.  
    8. function gotoIndex(idx) {
    9. var pos = view.contentY;
    10. var destPos;
    11. view.positionViewAtIndex(idx, ListView.Beginning);
    12. destPos = view.contentY;
    13. anim.from = pos;
    14. anim.to = destPos;
    15. anim.running = true;
    16. }
    17.  
    18. GridView{
    19. id: view
    20. anchors.fill: parent
    21. model: 200
    22. delegate: Text { text: index }
    23. }
    24.  
    25. MouseArea {
    26. anchors.fill: parent
    27. onClicked: gotoIndex(30)
    28. }
    29.  
    30. NumberAnimation { id: anim; target: view; property: "contentY"; duration: 500 }
    31. }
    To copy to clipboard, switch view to plain text mode 
    Worked like a charm!
    Thanks

  4. #4
    Join Date
    Feb 2015
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Animate ListView positionViewAtIndex

    In case anyone comes across the same issue:
    do NOT do
    Qt Code:
    1. function gotoIndex(idx) {
    2. var pos = view.contentY;
    3. var destPos;
    4. view.positionViewAtIndex(idx, ListView.Beginning);
    5. destPos = view.contentY;
    6. anim.from = pos;
    7. anim.to = destPos;
    8. anim.running = true;
    9. }
    To copy to clipboard, switch view to plain text mode 

    instead use:
    Qt Code:
    1. function gotoIndex(idx) {
    2. anim.running = false
    3. var pos = view.contentY;
    4. var destPos;
    5. view.positionViewAtIndex(idx, ListView.Beginning);
    6. destPos = view.contentY;
    7. anim.from = pos;
    8. anim.to = destPos;
    9. anim.running = true;
    10. }
    To copy to clipboard, switch view to plain text mode 

    If you wonder why, well I copied the original and implemented onWheel scrolling, when scrolling released the event again, the view go stuck since the animation was not finished, with adding on top the anim.running=false, you cancel the old animation and continue with the new one actually
    Last edited by anda_skoa; 7th February 2015 at 09:25. Reason: changed [quote] to [code]

Similar Threads

  1. animate buttons
    By kenouz1234 in forum Qt Programming
    Replies: 2
    Last Post: 8th November 2010, 12:23
  2. Animate in Dialog
    By wirasto in forum Newbie
    Replies: 1
    Last Post: 11th December 2009, 11:34
  3. animate items
    By ensky_cy in forum Qt Programming
    Replies: 2
    Last Post: 4th December 2009, 07:31
  4. animate a window
    By iGoo in forum Qt Programming
    Replies: 4
    Last Post: 27th June 2006, 10:46
  5. save animate to gif
    By Dmitry in forum Qt Programming
    Replies: 2
    Last Post: 16th February 2006, 16:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.