Results 1 to 6 of 6

Thread: Dynamic translation - Dialog windows

  1. #1
    Join Date
    Apr 2015
    Posts
    27
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Smile Dynamic translation - Dialog windows

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic translation - Dialog windows

    Quote Originally Posted by Wer_Bn View Post
    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

    Quote Originally Posted by Wer_Bn View Post
    So, what should I do?
    Retranslate them manually? With something like this for every label:
    Qt Code:
    1. ui->thisLabel->setText(tr("Hello this is really not good looking"));
    To copy to clipboard, switch view to plain text mode 
    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,
    _

  3. #3
    Join Date
    Apr 2015
    Posts
    27
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic translation - Dialog windows

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic translation - Dialog windows

    Quote Originally Posted by Wer_Bn View Post
    How do I know it's a form class?
    Does it have an associated .ui file?

    Quote Originally Posted by Wer_Bn View Post
    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,
    _

  5. #5
    Join Date
    Apr 2015
    Posts
    27
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic translation - Dialog windows

    /************************************************** ******************************
    ** 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("IConfigWi ndow", "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?

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic translation - Dialog windows

    How do you try to call it?

    Cheers,
    _

Similar Threads

  1. [Solved] QToolButton Dynamic translation
    By Osper in forum Qt Programming
    Replies: 0
    Last Post: 30th June 2014, 12:09
  2. Problem with dynamic translation
    By keo in forum Qt Programming
    Replies: 2
    Last Post: 29th July 2009, 10:36
  3. Dynamic translation for ComboBox
    By Rakesh_Kumar in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2009, 11:27
  4. How avoid translation of dynamic properties
    By thomas_-_s in forum Qt Tools
    Replies: 1
    Last Post: 19th October 2008, 22:02
  5. Replies: 27
    Last Post: 16th May 2008, 07:33

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.