无法将 fcitx 与自行编写的 Qt 应用程序一起使用 [英] Can't use fcitx with self-written Qt app

查看:48
本文介绍了无法将 fcitx 与自行编写的 Qt 应用程序一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 pyqt5,但不知何故,我无法在由 QTextEdit 或 QLineEdit 创建的文本框中使用 fcitx,尽管 fcitx 可以与其他 Qt 应用程序(如 Goldendict 或 kate)一起正常工作.但后来我发现 fcitx 也不适用于另一个使用 Qt 5.10 的名为 Retext 的 Qt 应用程序.我想这可能与最新版本的 Qt 左右有关.

I am learning pyqt5 and somehow I can't use fcitx in the text box created by QTextEdit or QLineEdit although fcitx works normally with other Qt apps like goldendict or kate. But later I found out that fcitx also doesn't work with another Qt app named Retext which uses Qt 5.10. Maybe this has something to do with the latest version of Qt or so I think.

这是我的代码,只是一个简单的文本框,没有别的:

Here's my code, just a simple textbox and nothing else:

import PyQt5.QtWidgets as QtWidgets
import sys

class App(QtWidgets.QWidget):
    def __init__(self):
        super().__init__()
        self.text = QtWidgets.QTextEdit()
        self.initUI()

    def initUI(self):
        vbox = QtWidgets.QVBoxLayout()
        vbox.addWidget(self.text)
        self.setLayout(vbox)
        self.show()

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec_())

推荐答案

感谢 @ekhumoro,我知道如何解决这个问题.只需将此行添加到 __init__ 函数即可启用输入法:

Thanks to @ekhumoro, I know how to fix this. Just enable input method by adding this line to the __init__ function:

self.setAttribute(Qt.WA_InputMethodEnabled)

然后这样做:

cp /usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontexts/fcitxplatforminputcontextplugin.so ~/.local/lib/python3.6/site-packages/PyQt5/Qt/plugins/platforminputcontexts
sudo chmod +x ~/.local/lib/python3.6/site-packages/PyQt5/Qt/plugins/platforminputcontexts/fcitxplatforminputcontextplugin.so

这篇关于无法将 fcitx 与自行编写的 Qt 应用程序一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆