What is the best way to create new QQuickItem on C++ side with the same properties as an existing one
-
I have a
QQuickItemfetched from C++ side like this.QQuickItem * my_item = qmlEngine->rootObjects()[0]->findChild<QQuickItem*>("ItemObjectName");my_itemis valid & has all the properties set on to it.Scenario
I have 2 windows which need thisQQuickItemto be drawn on alterantively. I want to render thismy_itemto a different window. This works perfectly fine as long as I set the Parent of themy_itemto the other window// the_other_window is a QQuickWindow QQuickWindow * the_other_window; // here I set parent my_item->setParentItem(the_other_window->contentItem());This requires me to do
setParentItemagain back tomy_item's original window otherwise it goes invisible on the original window. This is working but gives me unnecessary dependency. Instead I am trying to create a copy of theQQuickItem& do asetParentItemon that. By copying like this:QQuickItem * item_copy = new QQuickItem(my_item);I want to make
item_copyas exactly the same asmy_item. I learnt thatQQuickItemis not copyable. So, want to set all properties ofmy_itemintoitem_copy. Thus recreatingmy_itemfrom scratch. How can I do this? What properties should I copy primarily? width, height, x, y & what else?
Is there a method to copy all the valid properties into this new one without copying each one by one?