简体   繁体   English

在不更改其父层次结构的第二个窗口上渲染QQuickItem

[英]Render a QQuickItem on a second window without changing its parent hierarchy

I have to render a QQuickItem owned by a particular window, into another. 我必须将一个特定窗口拥有的QQuickItem渲染到另一个窗口中。 Basically MyQQuickItem owned by window1 to be rendered on window2. 基本上,window1拥有的MyQQuickItem将在MyQQuickItem上呈现。 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. 但这要求我在将父项从window1设置为window2并再次返回之间进行几次切换。

Question: 题:
Is there some other way to share MyQQuickItem between the 2 windows? 还有其他方法可以在两个窗口之间共享MyQQuickItem吗? Or is it possible display MyQQuickItem on the both the windows alternatively without having to change the parent hierarchy ? 还是可以在两个窗口上交替显示MyQQuickItem 而不必更改父级层次结构

You might use grabToImage() and display the grabbed image on your second window. 您可以使用grabToImage()并将grabToImage()的图像显示在第二个窗口中。
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. 我不知道您的情况,但最好是让同一个组件的两个实例显示相同的数据模型-可以禁用一个输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM