如何从 QML 中创建新窗口? [英] How can I create a new window from within QML?

查看:75
本文介绍了如何从 QML 中创建新窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法创建一个全新的窗口实例,作为 QmlApplication 中主 QML 窗口的子窗口?

Is there a way to create a completely new window instance, as a child window of the main QML window in a QmlApplication?

// ChildWindow.qml
Rectangle {
    id: childWindow
    width: 100
    height: 100
    // stuff
}

// main.qml
Rectangle {
    id: window
    width: 1000
    height: 600

    MouseArea {
        anchors.fill: parent
        onClicked: createAWindow(childWindow);
    }
}

我试图避免编写 Q_OBJECT 类只是为了在新的 QmlApplicationViewer 中实例化新窗口.

I am trying to avoid writing a Q_OBJECT class just for instanciating the new window within a new QmlApplicationViewer.

推荐答案

仅使用内置 QML 功能无法创建顶级窗口.

There is no way to create top-level windows using only built-in QML functionality.

然而,Qt Labs 上有一个名为 Desktop 的项目组件,其中包含一个 窗口组件,它允许您创建新的顶级窗口.

However there's a project on Qt Labs called Desktop Components, which among other things contains a Window component, which allows you to create new top-level windows.

这篇关于如何从 QML 中创建新窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆