How to correctly subscribe to changes in QQuickItem::childItems?
-
Hi everyone :)
I'm trying to implement custom positioner (i.e. like QML Row or Column) in C++ (inherited from QQuickItem) which would place children items in a honeycomb pattern. I want then expose it to QML and use it somewhat like this:HoneycombLayout { Repeater { model: someModel delegate: Cell {objectName: "#cell" + index} } }
So far I'm stuck with getting notified when the order of children items of HoneycombLayout changes. I tried to catch children updates using childrenChanged signal and by overriding itemChange method but in both cases last I update I receive happens when childItems list has first item (item which is supposed to be first) at the end of the list.
The ordering is getting fixed at some point (I checked this by repeatedly printing objectNames of items in childItems list in timer) but my handlers are not called when this happens and thus positioning is not updated.NOTE: I looked through implementation of standard QML positioners but they all seem to rely on private Qt which I would prefer not to use unless there is no other option.
I would greatly appreciate any suggestions :)
-
After looking through implementation of Qt positioners (qquickpositioners.* in qtdeclarative) I have found that the positioning itself is done in updatePolish method while in itemChange and onCompleted methods positioning is schedule and polish is called.
At this point I don't completely understand how it works, but it resolved my problem and I didn't have to resort to using qt private modules.