PyQt: translate standard buttons

How can I easily translate standard buttons (Yes, No) from a QMessageBox? I cannot use self.tr for these arguments, so I would like to achieve this in another simple way. Should I use the whole translation system?

+3
source share
4 answers

Here is how I did it:

First you need to copy the file qt_LOCALE.qmto your application directory. My was:

cp /usr/share/qt4/translations/qt_fr.qm .

Secondly, you need to download a translator for your application.

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_())
+9
source

, ? , .

+3

:

mymessagebox.button(mymessagebox.Yes).setText("Yes, please!")
mymessagebox.button(mymessagebox.No).setText("No, thanks.")

. QMessageBox .

+2

, Yes/No , . .

: , question() .., . , "" / "" ( , , , "" "" ). QMessageBox. , .

0

Source: https://habr.com/ru/post/1722479/


All Articles