有时 QtCreator 无法识别某些类型/属性,主要是 Qt4.x 中不存在的类型/属性,但这并不意味着您不能使用它们,所以是的,'Window' 是未知的,就像属性'antialiasing' , 'fontSizeMode' 或 'active' 是,但你可以使用它们,这是 QtQuick.Window 2.0 的使用示例:
import QtQuick 2.0
import QtQuick.Window 2.0
Window {
id: win1;
width: 320;
height: 240;
visible: true;
color: "yellow";
title: "First Window";
Text {
anchors.centerIn: parent;
text: "First Window";
Text {
id: statusText;
text: "second window is " + (win2.visible ? "visible" : "invisible");
anchors.top: parent.bottom;
anchors.horizontalCenter: parent.horizontalCenter;
}
}
MouseArea {
anchors.fill: parent;
onClicked: { win2.visible = !win2.visible; }
}
Window {
id: win2;
width: win1.width;
height: win1.height;
x: win1.x + win1.width;
y: win1.y;
color: "green";
title: "Second Window";
Rectangle {
anchors.fill: parent
anchors.margins: 10
Text {
anchors.centerIn: parent
text: "Second Window"
}
}
}
}
您只需要将 Window 项作为根对象,并且可以将其他 Window 项嵌入其中。