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中修复。
这篇博客探讨了在Qt5环境中,当TextField位于ListView中时,设置焦点导致无法输入中文的问题。作者提供了两种解决方法:1) 在ListView外部创建一个TextInput并设置其focus为true,然后将其visible设为false;2) 这可能是由于Qt5.15.1的已知bug,但在5.15.2中已修复。文章提示读者注意此类问题,并提供了相应的解决策略。
1027

被折叠的 条评论
为什么被折叠?



