插入符号位置 QtQuick TextField
Caret location QtQuick TextField
如何设置文本字段的插入符位置,
例如,当 onClicked 触发时,将插入符号位置设置为文本字段中的某个位置:
TextField {
id: fromDateTxt
inputMask: "0000-00-00"
MouseArea{
anchors.fill: parent
onClicked: {
//set caret location to somewhere in start or middle
}
}
}
您可以使用 cursorPosition
属性 (See docs)
onClicked: {
//set caret location to end
cursorPosition = text.length
focus = true
}
编辑:添加 focus = true 以便能够立即键入
如何设置文本字段的插入符位置,
例如,当 onClicked 触发时,将插入符号位置设置为文本字段中的某个位置:
TextField {
id: fromDateTxt
inputMask: "0000-00-00"
MouseArea{
anchors.fill: parent
onClicked: {
//set caret location to somewhere in start or middle
}
}
}
您可以使用 cursorPosition
属性 (See docs)
onClicked: {
//set caret location to end
cursorPosition = text.length
focus = true
}
编辑:添加 focus = true 以便能够立即键入