[英]How to create QQuickWindow as a child from a C++ extended QQuickItem?
此問題是由以下QML激發的:
ApplicationWindow {
Rectangle {
Text { text: "Hello World" }
}
Item {
// I do something
Window {
Text { text: "Hello world too!" }
}
}
}
在此示例中,在項目內部有一個應用程序窗口,然后是第二個窗口。 我試圖復制這種用法,但通過實例化一個QQuickWindow
擴展的內部QQuickItem
,但按照文檔我不能因為QQuickItem
的類型是不QWindow
。 我想要的是這樣的:
class Foo : public QQuickItem {
private:
QQuickWindow * childWindow;
public:
Foo(QQuickItem * parent = 0) : QQuickItem(parent) {
childWindow = new QQuickWindow();
childWindow->setParent(this);
// Add custom items to childWindow
}
}
不幸的是,這再次在childWindow->setParent(this)
處失敗,因為QQuickItem
不會擴展QWindow
。 我怎么能以類似的方式做到這一點?
Window
不是該項目的子項,也不是使用以下代碼容易看到的任何元素的子項:
ApplicationWindow {
width: 100
height: 100
visible: true
Rectangle {
Text { text: "Hello World" }
}
Item{
id: item
Window{
id: new_window
visible: true
color: "red"
Component.onCompleted: console.log("new_window :",new_window.parent)
}
Component.onCompleted: console.log("item :", item.parent)
}
}
輸出:
qml: item : ContentItem_QMLTYPE_10(0x56353791dbe0)
qml: new_window : undefined
顯然,可以看到Item
是contentItem
的子contentItem
,而Window
沒有父級。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.