问题:Phytium/FT-2000 | KylinOS V4 平台 使用Qt 5.6.1 开发图形界面的应用程序,使用了QPlainTextEdit 控件,在调用该控件的 setReadOnly(true)后,再调用 setReadOnly(false)之后,在该控件内输入文本时就不能输入汉字了。更具体来说,上述操作后,热点在此控件时,无法切换输入法;即使上述操作前,事先切换到中文输入法,在输入的时候,控件内直接显示输入的英文字符。
分析:
bing搜索"qt qplaintextedit输入中文",其中类似的一个链接是qt qplaintextedit输入中文_QQuickWidget中文输入法问题的正确解法_柯布西耶的博客-CSDN博客QQuickWidget中文输入法问题的正确解法本文分享特定问题的解法,用不到的可以忽略。Qt的bug使用QQuickWidget的时候,遇到过这个问题:界面的TextInput 或者TextEdit, 鼠标点击聚焦后,切换为光标输入状态,此时切换系统中文输入法,会发现无法输入。(系统任务栏的输入法状态是正确的,界面上输入字符,直接显示英文,无法显示输入法的候选框)需要把界面切到其它软件,再切换回...https://blog.csdn.net/weixin_28704239/article/details/113314537看内容有点小麻烦。
bing再搜索“qplaintextedit cannot input chinese after set readonly”,返回的一条类似的链接是
vanleo2001 commented Jul 25, 2018 •
Please review this QT5 bug: [QTBUG-55699] Japanese IME is disabled for QPlainTextEdit after read-only flag is toggled - Qt Bug Tracker |
嗯,有启发。
解决:在代码中,把需要调用setReadOnly()的位置,连续调用两次setReadOnly(),测试恢复正常,可以随心所欲输入汉字了。