[Interest] How to set a QObject extended type to a property var on Qml from C++

Nuno Santos nunosantos at imaginando.pt
Thu Apr 20 12:50:58 CEST 2017


Hi,

I’m creating a new kind of GridView because the one bundled with Qt/Qml doesn’t offer 2D high performance scrolling.

GridView layouts items in a flow style, breaking line when it overflows. This allows scrolling in just 1D. Two make it 2D, you will be force to draw items that you don’t see by extending the grid view width/height and using a flickable over it to control GridView scrolling. The second problem is that the binding is already made for all items. If you have thousands of items this can cost valuable CPU cycles. This is specially important when you are running on mobile devices.

I need a high performance 2D scrollable grid that is able to show thousands of items without rendering and binding them all at the same time. Therefore, it performs a culling operation to show only the visible ones.

I have analysed the source code for GridView but it has a massive amount of work not even taking into consideration the fact it extends flickable. I’m trying to make things more simple and I have a working prototype for this but now I’m facing some problems.

- While I was able to create the delegate concept, modelData and index properties are not available on the delegate. How do you make that magic happen? Simple way alternatives.

- Considering I’m not able to replicate the modelData and index mechanism. How can I pass a QObject extended type to a property var on Qml. The idea is to enable/disable the binding for the visible/not visible items at each update

Instead of explaining all I am doing, you will find the source code here -> https://pastebin.com/4cgrpbdX <https://pastebin.com/4cgrpbdX>

Right now, I have a really simple Rectangle delegate on my grid. It has a property var model property to which I want to assign my custom type LKClipSlot which extends QObject, however, doing:

item->setProperty("model", QVariant(static_cast<QObject*>(slot)));

doesn’t seem to be valid... 

Suggestions?

Thanks,

Regards,

Nuno



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170420/1e277fc8/attachment.html>


More information about the Interest mailing list