[PyQt] Translation not working for QSystemTrayIcon
Zdenko Podobny
zdenop at gmail.com
Thu Mar 21 16:42:48 GMT 2019
Thanks for suggestion. I thought (based on some example) that Qt is able to
change translation on the fly, so order is not imported. But it is.
+ I need to add app.installTranslator(appTranslator). Finale working
example (relevant part) is:
app = QtWidgets.QApplication(sys.argv)
appTranslator = QtCore.QTranslator()
loaded = appTranslator.load('sk_SK.qm')
app.installTranslator(appTranslator)
print("Translation loaded:", loaded)
if loaded: # test translating:
_translate = appTranslator.translate
print("should NOT be 'Settings...': " +
_translate("SystemTrayIcon", "Settings..."))
widget = QtWidgets.QWidget()
trayIcon = SystemTrayIcon(QtGui.QIcon('logo.ico'), widget)
trayIcon.show()
sys.exit(app.exec_())
Zdenko
št 21. 3. 2019 o 13:18 Dmitry Shachnev <mitya57 at ubuntu.com> napísal(a):
> Hello,
>
> On Thu, Mar 21, 2019 at 09:32:37AM +0100, Zdenko Podobny wrote:
> > I am not sure what I am doing wrong, but translation is not working for
> my
> > QSystemTrayIcon app. Here is my testing code:
> >
> > [...]
> > app = QtWidgets.QApplication(sys.argv)
> > widget = QtWidgets.QWidget()
> > trayIcon = SystemTrayIcon(QtGui.QIcon('logo.ico'), widget)
> > qtTranslator = QtCore.QTranslator()
> > appTranslator = QtCore.QTranslator(app)
> > loaded = appTranslator.load('sk_SK.qm')
> > [...]
>
> Try creating SystemTrayIcon after you load the translation, not before.
>
> --
> Dmitry Shachnev
> _______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20190321/fcd1d53e/attachment.html>
More information about the PyQt
mailing list