• 4546阅读
  • 1回复

[提问]关于一个QML使用另一个QML文件作为组件时出的问题 [复制链接]

上一主题 下一主题
离线clannadzy
 

只看楼主 倒序阅读 楼主  发表于: 2015-05-09
关键词: QML
Button.qml

  1. Rectangle{
  2.     id:button
  3.     property alias imageSource: btnImage.source
  4.     property alias btnWidth: button.width
  5.     property alias btnHeight: button.height
  6.     //property alias btnMouseAreaClicked: btnMa.onClicked
  7.     signal sendSignal(string msg)
  8.     Rectangle{id:btnShade;anchors.fill: button;
  9.         radius: 10;color: "lightBlue";opacity: 0
  10.     }
  11.     Image {id: btnImage; anchors.horizontalCenter: button.horizontalCenter}
  12.     MouseArea{id:btnMa;     anchors.fill: parent;}
  13.     states: [
  14.         State {
  15.             name: "pressed";when: btnMa.pressed == true
  16.             PropertyChanges {target: btnShade;opacity : 0.4}
  17.         }
  18.     ]
  19. }

调用Button.qml的base.qml:
  1. Button{
  2.             id:sendBtn
  3.             btnWidth: 107; btnHeight: 71
  4.             anchors{top:parent.top; topMargin: 50; left: parent.left; leftMargin: 50}
  5.             imageSource: "qrc:/imageIcon/fasong.png"
  6.         }

我目前对于这种组件的使用的感觉就是可以让单个QML文件不会太长。我想让base.qml里的button(不止上面贴出的那一个),根据QML发出的不同信号,通过信号和槽调用C++槽函数。因为MouseArea在Button.qml中,所以我给onclicked取了别名,但是取名时就感觉有问题,IDE没有提示btnMa有一个onClicked的属性,暂时忽略。但是在base.qml中填写btnMouseAreaClicked后,QML无法运行。请问前辈们,如何对MouseArea的onClicked进行类似区别名这样的操作呢?
离线彩阳

只看该作者 1楼 发表于: 2015-05-09
不要将onClicked取别名。
直接信号连接信号就好了。
Button顶层定义n个信号。
Button内部的MouseArea在onClicked的时候调用顶层的若干信号,形成差异。
上海Qt开发联盟,热忱地欢迎你的加入!
快速回复
限100 字节
 
上一个 下一个