qt中TextField或TextInput输入框无法输入中文解决办法

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值