我有以下 qml 文件:
import QtQuick 1.0
Component{
Column{
id: interHeader;
Item{
id:interItem
height: 300
width: 200
Text{
id:title
text:"Text"
anchors.centerIn: parent
font.bold: true
elide:"ElideRight"
color: "Black"
}
}
Item {
width: parent.width
height: 100
//onClick event
MouseArea {
anchors.fill: parent
onClicked:{
console.log("Ok");
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题是我需要为 interItem 分配一些 KeyNavigation。我想从另一个 qml 文件访问 interItem。如何才能做到这一点?
小智 2
Component在完全独立的 QML 文件中使用确实没有任何好处。删除组件并使用大写字母命名您的 Qml 文件 - 例如 InterHeader
property然后在你的根项目下定义一个。例如:
import QtQuick 1.0
Item {
id: interHeader
property variant keyActionUp
Keys.onUpPressed: keyActionUp
}
Run Code Online (Sandbox Code Playgroud)
或者
您可以使用该Connections函数对来自 interHeader 的信号执行回调。
http://doc.qt.nokia.com/4.7-snapshot/qml-connections.html