4

When running pyuic5 command and generating a python file from QT designer UI file there is a retranslateUi function.

def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))

Is this function for multi language support and can I safely delete this function if I have no interest in multi language?

I am adding GUI widgets in a loop so this function would be a hassle to implement in my code.

Lightsout
  • 3,454
  • 2
  • 36
  • 65
  • No, you cannot safely delete it, because It will always be called by `setupUi` - even when there are no translatable strings. And, more general;ly, there is never any good reason to edit the module generated by pyuic. Instead, you should import the gui class it contains, and use it in the ways suggested by the 2nd & 3rd examples shown [here](https://www.riverbankcomputing.com/static/Docs/PyQt5/designer.html#using-the-generated-code). Also note that even if you don't want multi-language support, `retranslateUi` is still needed for setting all the user-visible strings. – ekhumoro Feb 25 '21 at 04:59

1 Answers1

1

This function is made to implement the multi-language support logic (See 1 and 2).

And you can remove it without problems.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • I doubt I can remove it without issue, if I ctrl+F for some label text I see that it is only present under def retranslateUI – ArduinoBen Apr 16 '22 at 09:08