Qt 我有一个onclick按钮,它可以向上移动一条线,如何使线在到达某个x,y值后不向上移动?
我通过画一个高度为1的矩形来画一条线。然后,我有一个onclick按钮,它通过减小y值向上移动该行。如何使线在达到某个y值后不向上移动Qt 我有一个onclick按钮,它可以向上移动一条线,如何使线在到达某个x,y值后不向上移动?,qt,qml,Qt,Qml,我通过画一个高度为1的矩形来画一条线。然后,我有一个onclick按钮,它通过减小y值向上移动该行。如何使线在达到某个y值后不向上移动 Item { Rectangle { id: rectangle color:"#ef5350" y: 50 width: parent.width height: 1 } Button { anchors.centerIn: parent
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值。使用属性管理偏移量并将其绑定到最大/最小值:
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
属性中移动逻辑:
onClicked: {
if (rectangle.offset == -50)
return
rectangle.offset-=10
}
杰克,欢迎来到苏。首先你必须阅读。至于你的问题,你必须提供并澄清你的问题,因为你完全不清楚你在谈论什么。什么线路?什么路线?你真正的目标是什么?你想归档什么?