Can't use fcitx with self-written Qt app

773 Views Asked by At

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_())
1

There are 1 best solutions below

1
On

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)

Then do this:

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