SquareButton.qml
import QtQuick 2.2 Rectangle{ id:root signal activated(real xPosition, real yPostion) signal deactivated 100;height: 100 MouseArea{ anchors.fill: parent onClicked: { console.log("xxx") onPressed: root.activated(mouseX,mouseY) onReleased:root.deactivated } } }
main.qml
import QtQuick 2.9 import QtQuick.Window 2.2 Window { visible: true 640 height: 480 title: qsTr("Hello World") SquareButton{ onActivated: console.log("xxxx"+xPosition+","+yPostion) onDeactivated: console.log("yyyy") } }
SquareButton中信号 activated 对应main.qml中 onActivated