[SOLVED] QListView scrolling animation



  • Hi,

    I want to have a QListView with scrolling animation when I select an item out of QListView visible range. It's done by default in QML with ListView, and I think it comes from Flickable inheritance.

    Where can I define the proper QPropertyAnimation ?
    Have I to reimplement QListView::scrollTo() or have I to manage animation in the QItemDelegate ?

    I don't understand when does the item container is painting because in my QItemDelegate::paint(..) reimplementation I never manage it. Can someone help me ?

    Regards



  • What you might be able to do, is something like this:

    • Get the position of the item to scroll to in your view (using QListView::visualRect())
    • Get a handle on the vertical scroll bar of the list view
    • Create a QPropertyAnimation to animate the value property of the vertical scroll bar to a value that will get your item into view

    Should be doable IMHO, but I have not tried it myself.



  • You can use QPropertyAnimation in your QListView itself. It animates the property of a widget in this case it is the QListView::verticalScrollBar() "value" property. The start value would be the current scrollbar's value and the end value would be the QPoint at which the clicked index is present in the listview. There are many ways to get the clicked index's position in the view. To get a QML like feel in the animation provide enough animation duration and a eye caching easing curve - QEasingCurve (my fav is OutQuad though :) ) - build easingcurve example under Examples/Animation to see different easing curves.

    Though I have not verified, better to look at signal clicked(const QModelIndex) and find your way out to get the position of the supplied index. Once you get the target point simply animate it. See http://doc.trolltech.com/4.7/qpropertyanimation.html

    I don't see any point why animation should penetrate to delegate, it is something to do with QListView itself, so handle it there itself.



  • It works nicely,
    thanks


Log in to reply
 

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