我通过绘制高度为1的矩形来绘制一条线。然后,我有一个onclick按钮,可通过减小其y值来向上移动该线。在达到某个y值后,如何使行不向上移动?
Item
{
Rectangle
{
id: rectangle
color:"#ef5350"
y: 50
width: parent.width
height: 1
}
Button
{
anchors.centerIn: parent
text: "Move line up"
onClicked: rectangle.y-=10
}
}
我希望我的行不超过特定的y值。
答案 0 :(得分:1)
使用属性来管理您的偏移并将其限制为最大/最小:
Access to XMLHttpRequest at 'http://localhost:51255/token'
from origin 'http://localhost:4200' has been blocked by CORS policy:
Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
您还可以在Rectangle {
property int offset: 0
id: rectangle
color: "#ef5350"
y: 70 + Math.max(offset, -5 * 10) // Not more than 5 hits
width: parent.width
height: 1
}
Button {
anchors.centerIn: parent
text: "Move line up"
onClicked: rectangle.offset-=10
}
属性中移动逻辑:
onClicked