PyQt:翻译标准按钮

gru*_*czy 4 python qt translation pyqt button

如何从QMessageBox轻松翻译标准按钮(是,否)?我不能在这些参数上使用self.tr,所以我想以其他简单的方式实现它.我是否必须使用整个翻译系统?

Nat*_*tim 10

我是这样做的:

首先,您需要将qt_LOCALE.qm文件复制到应用程序目录.我的是:

cp /usr/share/qt4/translations/qt_fr.qm .
Run Code Online (Sandbox Code Playgroud)

其次,您需要为您的应用程序加载翻译器.

application = QApplication(argv)

locale = QLocale.system().name()
qtTranslator = QTranslator()
if qtTranslator.load("qt_"+locale):
    application.installTranslator(qtTranslator)

main_window = QMainWindow()
main_window.show()

exit(application.exec_())
Run Code Online (Sandbox Code Playgroud)


bal*_*pha 5

最快的方法是这样的:

mymessagebox.button(mymessagebox.Yes).setText("Yes, please!")
mymessagebox.button(mymessagebox.No).setText("No, thanks.")
Run Code Online (Sandbox Code Playgroud)

有关所有可能的标准按钮,请参阅 QMessageBox 文档。