我有一个使用矩形的基本自定义按钮radius: width/2.现在我添加一个MouseArea按钮.然而,它MouseArea有一个方形的形状.这意味着当我在圆形按钮外稍微点击时,也就是在圆形按钮周围的假想方块的角落中,也会触发click事件.我可以以某种方式制作MouseArea圆形吗?
import QtQuick 2.7
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
title: qsTr("TestApp")
Rectangle {
id: background
anchors.fill: parent
color: Qt.rgba(0.25, 0.25, 0.25, 1);
Rectangle {
id: button
width: 64
height: 64
color: "transparent"
anchors.centerIn: parent
radius: 32
border.width: 4
border.color: "grey"
MouseArea {
anchors.fill: parent
onPressed: button.color = "red";
onReleased: button.color = "transparent";
}
}
}
}
Run Code Online (Sandbox Code Playgroud)