Rectangle{
id: inputSideRec
anchors.top: parent.top
anchors.topMargin: 9
anchors.left: parent.left
anchors.leftMargin: 9
width: 402
height: 30
border.width: 1
border.color: addressRec.text === "" ? "red" : "#000000"
}
TextField{
id: addressRec
anchors.top: inputSideRec.top
anchors.topMargin: 1
anchors.left: inputSideRec.left
anchors.leftMargin: 1
width: 400
height: 28
anchors.margins: 2
focus: true //--------------------------要把焦点给到TextField才可以输入中文
text: "此处接收上一页面的当前地址"
font.pixelSize: 12
selectByMouse: true //是否可以选择文本
selectionColor: "#999999"//选中背景颜色
background: Rectangle { color: "#F3F3F3" }
activeFocusOnTab: true
}
tip : rectangle是为了给输入框一个边框
如果textInput TextField 在ListView中,则设置focus的方法失效。仍然无法输入中文
这种情况的处理办法:
1、在ListView外写一个TextInput
2、将这个TextInput的focus设置为true
3、设置这个TextInput的visible为false
即可。
具体原因不知。
网上搜索到的解释是:此bug为qt5.15.1自身bug, 在5.15.2中修复。