[Interest] Call retranslateUi() from UI generated/loaded directly from *.ui
Tony Rietwyk
tony at rightsoft.com.au
Sat May 1 18:37:20 CEST 2021
Did you try "loader.setTranslationEnabled(true);" before loader.load?
HTH, Tony
On 1/05/2021 10:43 am, Nicholas Yue wrote:
> I tried enabling setLanguageChangeEnabled(true) but I don't see my
> label updating, do I have to write some handler for that event and go
> through to update each widget text ? Apologies, I am new to translation.
>
> ```
> #include"MainWindow.h"
> #include<QVBoxLayout>
> #include<QDebug>
> #include<QUiLoader>
> #include<QFile>
> #include<QWidget>
> #include<QApplication>
> MainWindow::MainWindow(QWidget*parent)
> :QMainWindow(parent)
> {
> QUiLoaderloader;
> QFilefile(":/designer/mainwindow.ui");
> file.open(QFile::ReadOnly);
> QWidget*widget=loader.load(&file,parent);
> loader.setTranslationEnabled(true);
> file.close();
> setCentralWidget(widget);
> ui_checkBox=findChild<QCheckBox*>("checkBox");
> QObject::connect(ui_checkBox,SIGNAL(clicked()),this,SLOT(doCheckBox()));
> }
> voidMainWindow::doCheckBox(){
> qDebug()<<"doCheckBox()called="<<ui_checkBox->isChecked();
> if(ui_checkBox->isChecked())
> {
> QStringlangFile=QString(":/language/.qm/mlc_de.qm");
> QTranslatortranslator;
> if(translator.load(langFile)){
> qDebug()<<"DESuccessful";
> boolinstalled=qApp->installTranslator(&translator);
> if(installed){
> qDebug()<<"DEinstalled";
> }
> }
> else
> {
> qDebug()<<"DEUnsuccessful";
> }
> }
> else
> {
> QStringlangFile=QString(":/language/.qm/mlc_C.qm");
> QTranslatortranslator;
> if(translator.load(langFile)){
> qDebug()<<"CSuccessful";
> boolinstalled=qApp->installTranslator(&translator);
> if(installed){
> qDebug()<<"Cinstalled";
> }
> }
> else
> {
> qDebug()<<"CUnsuccessful";
> }
> }
> }
> ```
>
> On Thu, 29 Apr 2021 at 23:39, Friedemann Kleint
> <Friedemann.Kleint at qt.io <mailto:Friedemann.Kleint at qt.io>> wrote:
>
> Hi,
>
> > I am developing an application where I am generating the UI via
> loading the *.ui rather than using uic to generate the
> source/header file.
>
> > I need to call retranslateUi to update my translation but most
> documentation talks about a generated method by uic
>
> It should automatically react to language change events, see:
>
> https://doc.qt.io/qt-6/quiloader.html#setLanguageChangeEnabled
> <https://doc.qt.io/qt-6/quiloader.html#setLanguageChangeEnabled>
>
> Regards, Friedemann
>
> --
>
> Friedemann Kleint
> The Qt Company GmbH
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org <mailto:Interest at qt-project.org>
> https://lists.qt-project.org/listinfo/interest
> <https://lists.qt-project.org/listinfo/interest>
>
>
>
> --
> Nicholas Yue
> Graphics - Arnold, Alembic, RenderMan, OpenGL, HDF5
> Custom Dev - C++ porting, OSX, Linux, Windows
> http://au.linkedin.com/in/nicholasyue
> <http://au.linkedin.com/in/nicholasyue>
> https://vimeo.com/channels/naiadtools
> <https://vimeo.com/channels/naiadtools>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210502/56abb143/attachment.html>
More information about the Interest
mailing list