我在 PyQt5 中使用site-packages/PyQt5/translations
文件夹中的 qt_xx.qm 的 QTextEdit、QPlainTextEdit 和 QTextBrowser 的翻译默认上下文菜单有问题。例如,它适用于 QLineEdit(这是相同的上下文菜单)。如何处理?
重现问题的代码:
# coding: utf-8
import sys
from PyQt5.QtCore import QLocale
from PyQt5.QtCore import QTranslator
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtWidgets import QWidget
from PyQt5.QtWidgets import QLineEdit
from PyQt5.QtWidgets import QTextEdit
from PyQt5.QtWidgets import QVBoxLayout
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
widget = QWidget()
lineEdit = QLineEdit()
textEdit = QTextEdit()
vbox = QVBoxLayout(widget)
vbox.addWidget(lineEdit)
vbox.addWidget(textEdit)
self.setCentralWidget(widget)
if __name__ == '__main__':
app = QApplication(sys.argv)
locale = QLocale.system().name()
qtTranslator = QTranslator()
if qtTranslator.load('C:/Python33/Lib/site-packages/PyQt5/translations/qt_' + locale):
app.installTranslator(qtTranslator)
mainWindow = MainWindow()
mainWindow.show()
app.exec_()