[Interest] Call retranslateUi() from UI generated/loaded directly from *.ui

2021-04-29 Thread Nicholas Yue
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

e.g.
void retranslateUi(QWidget *Form)

  In my situation, how should I retranslate my UI ?

Cheers
-- 
Nicholas Yue
Graphics - Arnold, Alembic, RenderMan, OpenGL, HDF5
Custom Dev - C++ porting, OSX, Linux, Windows
http://au.linkedin.com/in/nicholasyue
https://vimeo.com/channels/naiadtools
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] Call retranslateUi() from UI generated/loaded directly from *.ui

2021-04-29 Thread Friedemann Kleint

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

Regards, Friedemann

--

Friedemann Kleint
The Qt Company GmbH

___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] Call retranslateUi() from UI generated/loaded directly from *.ui

2021-04-30 Thread Nicholas Yue
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 

#include 

#include 

#include 

#include 

#include 


MainWindow::MainWindow(QWidget *parent)

: QMainWindow(parent)

{

QUiLoader loader;

QFile file(":/designer/mainwindow.ui");

file.open(QFile::ReadOnly);

QWidget *widget = loader.load(&file, parent);

loader.setTranslationEnabled(true);

file.close();

setCentralWidget(widget);


ui_checkBox = findChild("checkBox");

QObject::connect(ui_checkBox, SIGNAL(clicked()),  this, SLOT(doCheckBox()));

}



void MainWindow::doCheckBox() {

qDebug() << "doCheckBox() called = " << ui_checkBox->isChecked();

if (ui_checkBox->isChecked())

{

QString langFile = QString(":/language/.qm/mlc_de.qm");

QTranslator translator;

if (translator.load(langFile)) {

qDebug() << "DE Successful";

bool installed = qApp->installTranslator(&translator);

if (installed) {

qDebug() << "DE installed";

}

}

else

{

qDebug() << "DE Unsuccessful";

}

}

else

{

QString langFile = QString(":/language/.qm/mlc_C.qm");

QTranslator translator;

if (translator.load(langFile)) {

qDebug() << "C Successful";

bool installed = qApp->installTranslator(&translator);

if (installed) {

qDebug() << "C installed";

}

}

else

{

qDebug() << "C Unsuccessful";

}

}

}

```


On Thu, 29 Apr 2021 at 23:39, Friedemann Kleint 
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
>
> Regards, Friedemann
>
> --
>
> Friedemann Kleint
> The Qt Company GmbH
>
> ___
> Interest mailing list
> Interest@qt-project.org
> 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
https://vimeo.com/channels/naiadtools
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] Call retranslateUi() from UI generated/loaded directly from *.ui

2021-05-01 Thread Tony Rietwyk

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
#include
#include
#include
#include
#include
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("checkBox");
QObject::connect(ui_checkBox,SIGNAL(clicked()),this,SLOT(doCheckBox()));
}
voidMainWindow::doCheckBox(){
qDebug()<<"doCheckBox()called="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 
mailto:friedemann.kle...@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


Regards, Friedemann

-- 


Friedemann Kleint
The Qt Company GmbH

___
Interest mailing list
Interest@qt-project.org 
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 

https://vimeo.com/channels/naiadtools 



___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest