效果展示
NewWindow.qml
import QtQuick 2.0
import QtQuick.Controls 2.0
ApplicationWindow {
id:newWindow
width: 200
height: 200
x:0
y:0
flags: Qt.FramelessWindowHint
color: "black"
Text{
text: "新窗口"
font{
bold: true
pixelSize: 18
}
color: "white"
anchors.centerIn: parent
}
}
Component_onCompleted.qml
import QtQuick 2.0
Item {
id:cocROOT
anchors.fill: parent
Component.onCompleted: {
var component = Qt.createComponent("NewWindow.qml")
var window = component.createObject(mainWindow)
window.show()
}
}
main.qml
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.0
Window {
id:mainWindow
width: 640
height: 480
visible: true
title: qsTr("Hello World")
Component_onCompleted{id:cocROOT}
}