I got quite an experience with mixing QML and C++, however recently run into trouble: I have GridLayout item inside QML code. Initially I populate it with QQuickItems (Rectangles containing icons in fact) from C++. This works and renders properly, including sizing, wrap on QML defined columns: property etc.
Now I need based on user interaction (mouse clicks on Rectangles) insert new rectangles in exact positions (in fact just before the clicked Rectangle). I have no problem with MouseEvent propagation, I am even able to pass any ammount of parameters (be it values or pointers to items) into my method to process. I just can not found "c++ wording" to make rectangles really rearrange.
I use the following code:
QQuickItem *icon = place(parent);
icon->stackBefore(insertBefore);
parent->update(); //(1)
GUI::programWindow->update(); //(2)
qDebug() << "\tCHILDS:" << parent->childItems(); //(3)
parent is pointer to GridLayout item passed from QML code (verified that it points where expected). place(parent) is my method, which loads proper icon based on this object, generates surrounding rectangle and returns pointer to it (i.e. *icon is Rectangle in fact). insertBefore is pointer to other rectangle inside the same GridLayout (passed through custom signal from my onClick handler). Double checked that it is child of proper GridLayout item.
Now I would expect, that Rectangle, that firstly got generated as the last of GridLayout children, gets "lighting fast" teleported before intended other Rect and GridLayout (knowing, that visual children order changed) will redraw new arrangement to screen. In fact I face to the newly created Rect visible as the last of GridLayout items.
Funny thing is, that output on line (3) shows proper, i.e. reordered order of children. So order of output from the parent->childItems() differs from what can be seen on screen. The lines commented (1) and(2) were my desperate attempts to make GridLayout to redraw, but no visible change appeared.
Does anybody have some experience with reordering GridLayout children? Is there some other, more proper, method to call instead of stackBefore()? Or am I missing some stupid, immediately visible thing :) ?
Thanks in advance for any clues.