将 MouseArea 扩展到组件之外
Extend MouseArea beyond component
我有一个宽度为 1(一条线)的矩形,它应该是可拖动的:
Rectangle {
id: recMark
border.width: 0
width: 1
height: parent.height
y: 0
color: "red"
opacity: 0.3
visible: true
MouseArea {
anchors.fill: parent
drag.target: recMark
drag.axis: Drag.XAxis
}
}
是否可以将鼠标区域扩展到矩形之外,例如3个像素左右吗?很明显,用鼠标很难打到正确的像素点。
您可以将负数 margins
添加到 MouseArea
:
MouseArea {
anchors.fill: parent
anchors.margins: -3
// ...
}
我有一个宽度为 1(一条线)的矩形,它应该是可拖动的:
Rectangle {
id: recMark
border.width: 0
width: 1
height: parent.height
y: 0
color: "red"
opacity: 0.3
visible: true
MouseArea {
anchors.fill: parent
drag.target: recMark
drag.axis: Drag.XAxis
}
}
是否可以将鼠标区域扩展到矩形之外,例如3个像素左右吗?很明显,用鼠标很难打到正确的像素点。
您可以将负数 margins
添加到 MouseArea
:
MouseArea {
anchors.fill: parent
anchors.margins: -3
// ...
}