I\'m writing a API to be used in the creation of Interfaces at work. The API allows the user to pick from a set of pre-built widgets and layouts so that multiple interfaces
I suspect this is due to the fact that:
m_pButton = new MyWidget(tr("TEST"));
defines a string in the context of MainWindow
, and you try to translate TEST
in the context of MyWidget
. You can circumvent this by using the static tr()
method on QObject
. This will define TEST
as a translation in the global QObject
context. This can be done by adapting the button widget creation code as follows:
m_pButton = new MyWidget(QObject::tr("TEST"));
and in MyWidget::retranslate()
:
setText(QObject::tr(name().toStdString().c_str()));
Note that you need to regenerate your translation files for this to work!