我有一个基本的自定义按钮,使用一个带有radius: width/2
的矩形。现在我给按钮添加了一个MouseArea
。但是MouseArea
是一个正方形形状。这意味着当我点击圆形按钮周围想象的正方形的角落时,也会触发点击事件。我怎么样才能让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";
}
}
}
}
clip: true
设置为button
,它会起作用吗?现在无法测试。 - folibisclip: true
,但问题仍然没有改变。谢谢。 - Varius