如何从C++扩展的QQuickItem创建QQuickWindow作为子窗口?
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!" }
}
}
}
在此示例中,有一个应用程序窗口,然后在项内有第二个窗口。我正在尝试复制这种用法,但是通过在扩展QQuickItem
中实例化QQuickWindow
,但根据文档,我不能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
的孩子,另一方面Window
没有父母。
相关文章:
- 如何在Qt窗口小部件中使用QStringView(或QStringRef)
- 问:如何使用C++中的按钮从窗口打开窗口
- SDL 窗口不会弹出
- 在createdialog创建的窗口中捕获用于编辑控件的OnMouseMove消息
- 如何在cpp文件之间切换窗口?在Qt中
- QuadTree只在窗口的右上角绘制
- VS Code "command":"make"与终端窗口中的命令行"make"不同
- 如何在C++中找到active directory中禁用和锁定的窗口帐户
- 处理闪烁窗口事件
- 如何通过按下第三个窗口中的按钮,将QString从一个窗口获取到另一个窗口
- C++win32 API创建多个类似视口的窗口
- SFML RenderWindow打开窗口需要很长时间
- 如何将不同的可执行文件合并到一个窗口框架中进行编码?像浏览器一样
- 获取 SFML 窗口的 HWND 和高可用性?
- 如何获取 GLFW 窗口 ID?
- GLEW/GLUT:调用init并创建一个窗口后,取消初始化并重新初始化?
- 用于窗口的 HID 终端
- SFML 文本未绘制在窗口上
- 如何为窗口截屏
- 如何从C++扩展的QQuickItem创建QQuickWindow作为子窗口?