[Interest] QML Listview delegate in C++

Bo Thorsen bo at vikingsoft.eu
Sat Jun 6 08:34:36 CEST 2015


Den 05-06-2015 kl. 23:04 skrev Simone:
> I'm facing a problem in my QML application. The target is an Arrm processor

Ah, the pirate processor :)

> (freescale iMX53) with not so much capabilities.
> My problem is that I have a quite complex listview delegate item, and I observe a cpu usage very high when scrolling my list with lot of items, penalyzing the smoothness of the scrolling.
> I was wondering if I can develop the delegate in C++ (with widgets) instead of pure QML since the creation of QML objects is (of course) slower.

No, you can't use widgets for this. Technically that might not be 
entirely accurate, but since we're talking performance, it is.

What you can do instead is to create a new kind of item yourself by 
subclassing QQuickItem and using native OpenGL rendering to do this. 
There are examples in the Qt dir that shows how to do this. You can also 
watch a talk from last years dev days about how to do this.

If you create a single item delegate that performs the entire painting 
without creating other objects, you probably can't do better. Now, 
wether this actually solves your problem

> Is there such possibility?
> Can I reasonably increase scroll performances?

Yes, that should be possible. I was not sure if the delegate was 
instantiated multiple times or reused, but a quick test with this shows 
that it's actually created over and over again:

import QtQuick 2.2

Rectangle {
     width: 360
     height: 360

     property int delegateCount: 0

     Component {
         id: itemDelegate
         Text {
             text: "I am item number: " + index
             Component.onCompleted: console.log("Instantiated delegate", 
++delegateCount)
         }
     }

     ListView {
         anchors.fill: parent
         model: 1000000
         delegate: itemDelegate
     }
}

I hope this helps,

Bo.

-- 
Viking Software
Qt and C++ developers for hire
http://www.vikingsoft.eu



More information about the Interest mailing list