我目前正在学习如何使用 QML 中的 Shapes 来绘制更高级的组件。我正在尝试创建一个如下所示的按钮:
当我尝试在 Shape 组件上应用 MouseArea 时,MouseArea 似乎无法捕获 Shape 上的事件。这是我的代码:
import QtQuick 2.13
import QtQuick.Shapes 1.13
Item
{
Shape
{
id: myShape
ShapePath {
id: myButton
strokeWidth:3.114000082015991
strokeColor: "#000"
miterLimit:7
fillColor: "#ccc"
capStyle:ShapePath.RoundCap
PathSvg {
path: "M392.4,205.9a132.34,132.34,0,0,1,31.7,49.2H575.6a289.67,289.67,0,0,0-12.9-49.2Z"
}
}
}
MouseArea
{
id: myMouseArea
anchors.fill: myShape
enabled: true
hoverEnabled: true
onEntered: myButton.fillColor = "yellow"
onExited: myButton.fillColor = "green"
}
}
所以我的问题是:是否可以首先使 Shape/ShapePath 可点击?如果是,该怎么做?