标题:关于一个QML使用另一个QML文件作为组件时出的问题
作者:clannadzy
日期:2015-05-09 15:26
内容:
Button.qml
Rectangle{
id:button
property alias imageSource: btnImage.source
property alias btnWidth: button.width
property alias btnHeight: button.height
//property alias btnMouseAreaClicked: btnMa.onClicked
signal sendSignal(string msg)
Rectangle{id:btnShade;anchors.fill: button;
radius: 10;color: "lightBlue";opacity: 0
}
Image {id: btnImage; anchors.horizontalCenter: button.horizontalCenter}
MouseArea{id:btnMa; anchors.fill: parent;}
states: [
State {
name: "pressed";when: btnMa.pressed == true
PropertyChanges {target: btnShade;opacity : 0.4}
}
]
}
调用Button.qml的base.qml:
Button{
id:sendBtn
btnWidth: 107; btnHeight: 71
anchors{top:parent.top; topMargin: 50; left: parent.left; leftMargin: 50}
imageSource: "qrc:/imageIcon/fasong.png"
}
我目前对于这种组件的使用的感觉就是可以让单个QML文件不会太长。我想让base.qml里的button(不止上面贴出的那一个),根据QML发出的不同信号,通过信号和槽调用C++槽函数。因为MouseArea在Button.qml中,所以我给onclicked取了别名,但是取名时就感觉有问题,IDE没有提示[color= ..
#1 [彩阳 05-09 18:32]
不要将onClicked取别名。
直接信号连接信号就好了。
Button顶层定义n个信号。
Button内部的MouseArea在onClicked的时候调用顶层的若干信号,形成差异。