为了做到这一点,我知道我需要使用一些 if 条件,如下所示。但看起来我做错了!
问题出if condition
在位置上还是位置上,我应该在哪里包含它?
Grid {
x: 5
y: 3
rows: 5
columns: 20
spacing: 10
Repeater {
id: rpt
model: 50
TextField {
width: 28
height: 50
color: "green"
text:{ "0000";
if(rpt.itemAt(index).text.length ==4)nextItemInFocusChain().forceActiveFocus()
}
font.pixelSize: 12
Keys.onEnterPressed: nextItemInFocusChain().forceActiveFocus()
validator: IntValidator {
bottom: -256
top: 256
}
}
}
}
您希望在 , 中的文本更改时做出反应TextInput
,因此在textChanged
信号处理程序的主体中:
TextField {
width: 28
height: 50
color: "green"
onTextChanged: {
if (text.length === 4) {
nextItemInFocusChain().forceActiveFocus()
}
}
}
查看更多关于QML 文档中的 JavaScript 表达式。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句