Alex Herbert
Alex Herbert

Reputation: 1

How to tackle dynamic translation of PyQt application whilst using QUiLoader

I would love some input into what the best way is to go about translating a widget in PyQt dynamically. I am aware of the retranslateUi() method, but this is not accessible when loading the .ui file (created in QtDesigner) directly. self.ui = self.loader.loadUi('HMI/ui/QtDesignerFiles/main_window.ui', self) You are not able to then do

self.ui.retranslateUi(self)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: 'MainWindow' object has no attribute 'retranslateUi'

I have created the .qm file and successfully installed it to get the translation for the text

self.ui.tr("File")
'Fichier'

From my research and reading it seems the only way I can best go about translating the widgets right now is to go through each one and translate it self.ui.file_menu.setTitle(QCoreApplication.translate("MainWindow", "File"))

Am I missing something or have I exhausted all possible ways without using pyuic and getting the .py files from the .ui files to then use retranslateUi()?

Upvotes: 0

Views: 20

Answers (0)

Related Questions