You don't have to comment out anything, just set new strings and window titles in event handler during LanguageChange event:
void MainWindow
::changeEvent(QEvent *e
) {
switch (e->type()) {
this->retranslate();
break;
default:
break;
}
}
void MainWindow::retranslate(){
ui->retranslateUi(this);
ui->pushButton->setText(tr("I changed the text"));
setWindowTitle(tr("This is the title I would like to be"));
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
this->retranslate();
break;
default:
break;
}
}
void MainWindow::retranslate(){
ui->retranslateUi(this);
ui->pushButton->setText(tr("I changed the text"));
setWindowTitle(tr("This is the title I would like to be"));
}
To copy to clipboard, switch view to plain text mode
In constructor call this->retranslate() and its done.
Bookmarks