可以插圖中的QML多個窗口,只是以同樣的方式,傳達你的任何其他兩者之間的溝通Items
通過引用它們或通過id
s或將它們分配給您稍後用於引用它們的屬性。 考點:
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
Item {
ApplicationWindow
{
id: appWindow
width: 500
height: 800
visible: true
ListModel {
id: lm
Component.onCompleted: {
for (var i = 0; i < 42; i++) append({ message: 'Hellow World ' + i })
}
}
ListView {
id: lv
width: 300
height: 800
model: lm
delegate: Button {
text: model.message
onClicked: secondWindow.text = text
}
}
}
ApplicationWindow
{
id: secondWindow
width: 500
height: 800
x: appWindow.x + 500
y: appWindow.y
visible: true
property alias text: label.text
Text {
id: label
anchors.centerIn: parent
}
}
}