Render a QQuickItem on a second window without changing its parent hierarchy

605 views Asked by At

I have to render a QQuickItem owned by a particular window, into another. Basically MyQQuickItem owned by window1 to be rendered on window2. This switch has to happen in my app repeatedly due to a certain functionality.

I do the following to achieve the goal & the code basically works fine.

Code:

MyQQuickItem * myQuickItem = qmlEngine->rootObjects()[0]->findChild<QQuickItem*>("myquickitemobject");
myQuickItem->setParentItem(window1->contentItem());

// do the required on window2

// then set window1 as parent back again
myQuickItem->setParentItem(window2->contentItem());

Problem:
Above technique functionally works fine. But this requires me to flip flop a few times juggling between setting parent item from window1 to window2 & back again.

Question:
Is there some other way to share MyQQuickItem between the 2 windows? Or is it possible display MyQQuickItem on the both the windows alternatively without having to change the parent hierarchy?

1

There are 1 answers

0
derM - not here for BOT dreams On

You might use grabToImage() and display the grabbed image on your second window.
This might not be ideal, performance wise. You can find some questions on how to do this on this site. Especially interesting might be this.

I don't know your case, but it might be better, to have two instances of the same component displaying the same data model - possible with input for one disabled.