PDA

View Full Version : Dynamic translation - Dialog windows



Wer_Bn
3rd June 2015, 15:46
Hello guys

I know how to translate my MainWindow:


myTranslator.load(":/languages/whateverLanguage.qm");


And then a changeEvent happens, where I filter it by QEvent::LanguageChange:


if(event->type() == QEvent::LanguageChange)
{
//here I set my special dynamic strings, for something not directly related with the .ui file
ui->retranslateUi(this);
}
QWidget::changeEvent(e);


The problem is that I use a different dialog in this application. And QDialog class has no retranslateUi function.

So, what should I do?
Retranslate them manually? With something like this for every label:

ui->thisLabel->setText(tr("Hello this is really not good looking"));

Or is there another way to automatically do this, like in MainWindow?

Thanks in advance

anda_skoa
3rd June 2015, 17:32
The problem is that I use a different dialog in this application. And QDialog class has no retranslateUi function.

retranslateUi is a function of the generate form class, not of QMainWindow.
It is therefore available for all widgets that are constructed vi



So, what should I do?
Retranslate them manually? With something like this for every label:


ui->thisLabel->setText(tr("Hello this is really not good looking"));


Well, "ui" looks like the pointer to a form class, so ui->retranslateUi(this);
But yes, if you don't have a form class, setting the strings again is the way to go.
retranslateUi does the same.

Cheers,
_

Wer_Bn
4th June 2015, 08:50
How do I know it's a form class?

It is derived from a QDialog and it has a .ui file associated with it.
But it certainly doesn't have retranslateUI

anda_skoa
4th June 2015, 11:17
How do I know it's a form class?

Does it have an associated .ui file?



It is derived from a QDialog and it has a .ui file associated with it.
But it certainly doesn't have retranslateUI
Can you attach the generated _ui.h file?

Cheers,
_

Wer_Bn
12th June 2015, 10:11
/************************************************** ******************************
** Form generated from reading UI file 'IConfigWindow.ui'
**
** Created by: Qt User Interface Compiler version 5.4.1
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
************************************************** ******************************/

#ifndef UI_ICONFIGWINDOW_H
#define UI_ICONFIGWINDOW_H

#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QDial>
#include <QtWidgets/QDialog>
#include <QtWidgets/QFrame>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QRadioButton>
#include <QtWidgets/QSlider>
#include <QtWidgets/QSpacerItem>
#include <QtWidgets/QVBoxLayout>

QT_BEGIN_NAMESPACE

class Ui_IConfigWindow
{
public:
QVBoxLayout *verticalLayout_2;
QLabel *warningConnectedLabel;
QHBoxLayout *horizontalLayout_6;
QHBoxLayout *horizontalLayout;
QLabel *referenceLabel;
QDial *referenceDial;
QLabel *label;
QLabel *label_3;
QSpacerItem *horizontalSpacer_4;
QVBoxLayout *verticalLayout;
QRadioButton *NormalPIRadioButton;
QRadioButton *OverridePIRadioButton;
QFrame *line_3;
QHBoxLayout *horizontalLayout_3;
QLabel *resistorLabel;
QSlider *resistorSlider;
QLabel *label_6;
QLabel *label_2;
QFrame *line_2;
QHBoxLayout *horizontalLayout_2;
QLabel *samplingFrequencyLabel1;
QLineEdit *samplingFrequencyLineEdit;
QLabel *samplingFrequencyLabel2;
QSpacerItem *horizontalSpacer_3;
QFrame *line_4;
QHBoxLayout *horizontalLayout_5;
QLabel *displayFrequencyLabel1;
QLineEdit *displayFrequencyLineEdit;
QLabel *displayFrequencyLabel2;
QSpacerItem *horizontalSpacer_2;
QFrame *line;
QHBoxLayout *horizontalLayout_4;
QSpacerItem *horizontalSpacer;
QPushButton *closeButton;

void setupUi(QDialog *IConfigWindow)
{
if (IConfigWindow->objectName().isEmpty())
IConfigWindow->setObjectName(QStringLiteral("IConfigWindow"));

// bla bla bla, configuration stuff


retranslateUi(IConfigWindow);
QObject::connect(referenceDial, SIGNAL(valueChanged(int)), label, SLOT(setNum(int)));
QObject::connect(resistorSlider, SIGNAL(valueChanged(int)), label_6, SLOT(setNum(int)));
QObject::connect(closeButton, SIGNAL(clicked()), IConfigWindow, SLOT(accept()));

QMetaObject::connectSlotsByName(IConfigWindow);
} // setupUi

void retranslateUi(QDialog *IConfigWindow)
{
IConfigWindow->setWindowTitle(QApplication::translate("IConfigWindow", "Interface Configuration", 0));
warningConnectedLabel->setText(QString());
referenceLabel->setText(QApplication::translate("IConfigWindow", "Reference", 0));
label->setText(QApplication::translate("IConfigWindow", "0", 0));
label_3->setText(QApplication::translate("IConfigWindow", "%", 0));
} // retranslateUi

};

namespace Ui {
class IConfigWindow: public Ui_IConfigWindow {};
} // namespace Ui

QT_END_NAMESPACE

#endif // UI_ICONFIGWINDOW_H


It is there... but I can't call it...
Why?

anda_skoa
12th June 2015, 14:04
How do you try to call it?

Cheers,
_