【发布时间】:2016-07-02 20:09:43
【问题描述】:
我有一个基本的自定义按钮,使用带有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会起作用吗?只是现在无法测试 -
@folibis:很遗憾没有。我已将
clip: true添加到我的按钮中,但问题仍然没有改变。谢谢。
标签: qt user-interface qml qtquick2