不同QML文件之间的参数互相调用
假设有两个qml文件,分别为A.qml和B.qml,其中A.qml代码实现为:
Rectangle {
id:aRec;
width:640;
height:480;
Button {
id:buttonA1;
width:30;
height:20;
}
Button {
id:buttonA2;
width:30;
height:20;
}
}
B.qml的代码实现为:
Rectangle {
id:bRec;
width:640;
height:480;
Button {
id:buttonB1;
width:30;
height:20;
}
Button {
id:buttonB2;
width:30;
height:20;
}
}
如果想要在A.qml中调用B.qml中的buttonB1的属性值,需要作如下修改:
Rectangle {
id:bRec;
width:640;
height:480;
Button {
id:buttonB1;
width:30;
height:20;
}
Button {
id:buttonB2;
width:30;
height:20;
}
A {
id:a
}
}
解释:B.qml修改之后,A相当于B的子控件,子控件可以调用父控件的所有全局变量值,即在A.qml中可以调用到例如buttonB1.width等属性。