Reputation: 41
On ubuntu, I developed an application using pyqt5, but it does not support Chinese input(My sogouPinyin input method cannot show Chinese context menu when I want to type text on my application). My OS supports Chinese input. How to fix it?
Upvotes: 2
Views: 780
Reputation: 41
sudo apt install fcitx-frontend-qt5 fcitx-libs-qt fcitx-libs-qt5
sudo cp /usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontexts/libfcitxplatforminputcontextplugin.so ${PYTHON_HOME}/lib/site-packages/PyQt5/Qt/plugins/platforminputcontexts/
os.environ['QT_IM_MODULE'] = 'fcitx'
in main file. (maybe not necessary.)Upvotes: 2
Reputation: 243907
sogouPinyin is based on Fcitx, so for the case of Qt applications the docs indicates that you have to use the flag QT_IM_MODULE
:
from PyQt5 import QtWidgets
if __name__ == '__main__':
import sys
import os
os.environ['QT_IM_MODULE'] = 'fcitx'
app = QtWidgets.QApplication(sys.argv)
w = QtWidgets.QWidget()
lay = QtWidgets.QVBoxLayout(w)
lay.addWidget(QtWidgets.QLineEdit())
lay.addWidget(QtWidgets.QTextEdit())
w.show()
sys.exit(app.exec_())
After the application is open you must place the focus in an editing widget such as QLineEdit, QTextEdit and press Ctrl + Space to enable it.
But you have to have installed fcitx-qt5 package:
On Ubuntu:
sudo apt-get install fcitx-qt5 fcitx fcitx-frontend-qt5
Upvotes: 1