[英]Binding Loop Error While Trying to Increment Progress
I am trying to show incremental changes on a progress bar by clicking a mouse area. 我试图通过单击鼠标区域在进度条上显示增量更改。 The code below compiles and changes the value of the progress bar from 0 to 0.25 after clicking the mouse area.
单击鼠标区域后,下面的代码编译进度栏并将其值从0更改为0.25。 But the change is not permanent.
但是这种改变不是永久的。 I am trying to increase the current each click by 0.25.
我试图将当前每次点击增加0.25。 I know my code is only setting the value to positive .25 each click.
我知道我的代码仅将每次点击的值设置为正.25。 I am just at a loss for how I might increment change in progress bar without global vars.
我不知如何在没有全局变量的情况下增加进度条的变化。 I included the transition to ensure the state change was irreversible, the code still compiles and runs the same.
我加入了过渡,以确保状态更改是不可逆的,代码仍然可以编译并运行。 There are two issues.
有两个问题。
ProgressBar{
id: progressBar
height: 20
anchors.top: parent.top
anchors.topMargin: 100
anchors.horizontalCenter: parent.horizontalCenter
opacity: 1
value: 0
states: State{
name: "PressedAlso"
when: mouseArea.pressed == true
PropertyChanges{
target: progressBar
value: + 0.25
}
}
transitions: Transition {
from: ""; to: "PressedAlso"; reversible: false
}
}
Your state PressedAlso
means: when the mouse button is pressed, the value is 0.25. 您的状态
PressedAlso
表示:当按下鼠标按钮时,该值为0.25。 Otherwise, the value is implicitly 0. 否则,该值隐式为0。
If you want to increment by 0.25 by pressing the mouse button, you can use onPressed
property in your MouseArea
: 如果要通过按鼠标按钮增加0.25,可以在
MouseArea
使用onPressed
属性:
MouseArea {
anchors.fill: parent
id: mouseArea
onPressed: progressBar.value += 1
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.