[Development] Improve performance (listview + onVerticalVelocityChanged)
Bernhard B
schluchti at gmail.com
Thu Jan 26 20:09:26 CET 2017
I think I solved my problem. In case someone is interested, that's my
solution:
//hide "back to top" button when movement ended and we are
//at index 0
onMovementEnded: {
if(indexAt(contentX, contentY) === 0){
backToTopButton.visible = false;
}
}
onFlickStarted: {
//when user scrolls fast enough up, show the tab bar
//and the "back to top" button
if(verticalVelocity < -flickTabBarTreshold) {
backToTopButton.visible = true;
tabBar.show();
}
//when user scrolls fast enough down hide "back to top" button
//and the tab bar
if(verticalVelocity > flickTabBarTreshold){
backToTopButton.visible = false;
tabBar.hide();
}
}
I don't know if this is the best solution, but it seems to work.
Thanks,
Bernhard
2017-01-26 15:38 GMT+01:00 Bernhard B <schluchti at gmail.com>:
> Hi,
>
> I am currently trying to optimize my Listview for performance. I already
> removed most of the bottlenecks by following the great recommendations at:
> http://doc.qt.io/qt-5/qtquick-performance.html
>
> However, there is one problem I don't how to solve. It's about this code
> part:
>
> ListView{
> clip: true
> property real flickTabBarTreshold;
>
> Component.onCompleted: {
> flickTabBarTreshold = (2/3) * maximumFlickVelocity;
> }
>
> onVerticalVelocityChanged: {
>
>
> //when user scrolls fast enough up, show the tab bar //and the "back to top" button
>
> if(verticalVelocity < -flickTabBarTreshold) {
> backToTopButton.visible = true;
>
> tabBar.show();
>
> }
>
>
>
> //when user scrolls fast enough down hide "back to top" button //and the tab bar
> if(verticalVelocity > flickTabBarTreshold){
>
> backToTopButton.visible = false;
>
> tabBar.hide();
>
> }
>
> //always disable "back to top button" when top reached if(indexAt(contentX, contentY) === 0) backToTopButton.visible = false;
>
> }
> }
>
> This part is one of the biggest performance bottlenecks at the moment (as
> it gets called a lot of times) and has a significant impact on the
> scrolling behavior (lagging).
>
> My idea was to put that code somehow in my C++ Listmodel and emit only a
> signal when something actually changed.
>
> For the last part
>
> //always disable "back to top button" when top reachedif(indexAt(contentX, contentY) === 0) backToTopButton.visible = false;
>
>
> I think it should be possible to check that in the
> QVariant <http://doc.qt.io/qt-5/qvariant.html> QAbstractItemModel::data(const
> QModelIndex <http://doc.qt.io/qt-5/qmodelindex.html> &*index*, int *role*
> = Qt::DisplayRole) const
>
> method. When index.row() === 0, I a signal will be emitted. In QML I am
> connecting on that signal and execute backToTopButton.visible = false;
>
> I haven't tested it yet, but I think it should work.
>
> For the other two conditions however, I am a little bit clueless.
>
> Does anyone of you guys maybe have an idea on how to improve that?
>
> Any help is really appreciated.
>
>
> Thanks,
>
> Bernhard
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20170126/70e892c8/attachment.html>
More information about the Development
mailing list