Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Translate Qt app
Qt 6.11 is out! See what's new in the release blog

Translate Qt app

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 3 Posters 4.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    Why is it odd ? It's a pretty simple way for the developer to know that the language changed and he can act accordingly. Not all widget have text to translate nor do they systematically need translation.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mostefa
      wrote on last edited by
      #3

      Hi @SGaist

      Thank you for your answer,

      Instead of calling changeEvent in every widget,

      Is there a way to call changeEvent just on my mainWindow like this, and then translate widget that need to be translated:

      void MyMainWindow::changeEvent(QEvent *e)
      {
          QWidget::changeEvent(e);
          switch (e->type())
          {
          case QEvent::LanguageChange:
          {
              ui->retranslateUi(this);
             // Here i want to translate or my child widgets
             widget1->retranslateUi//or something like this
             widget2->retranslateUi//or something like this
      
      ...
              break;
          }
          default:
              break;
         }
      }
      
      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #4

        Sure you can do it like that but that would mean adding add a method to all your other widgets. However, IIRC, widgets created through designer already handle that part so there's no need for that.

        Do you have other widgets that are not designer based ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mostefa
          wrote on last edited by
          #5

          @SGaist

          No,all my widgets that need to be translated are based on qt designer,

          Widgets does not have retranslateUi method , so i don't know how to tell my widgets to be translated from my mainWindow

          case QEvent::LanguageChange:
            {
                ui->retranslateUi(this);
               // Here i want to translate or my child widgets
               widget1->//looking for the function to tell widget to be translated
               widget2->//looking for the function to tell widget to be translated
          
          ...
                break;
            }
          

          any idea how to do that ?

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #6

            No it's a method implemented in the ui object class.

            If you don't want that change event in all your classes, like I wrote before, you have to add a method to each of your widget calling ui->retranslateUi(this).

            Thus adding:

            void MyWidget::changeEvent(QEvent *event)
            {
                if (event->type() == QEvent::LanguageChange) {
                    ui->retranslateUi(this);
                } else
                    QWidget::changeEvent(event);
            }
            

            to your widgets would be a lot cleaner.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • M Offline
              M Offline
              mostefa
              wrote on last edited by
              #7

              @SGaist

              Ok , thank you for your help,

              Well i think that i will reimplement the changeEvent for every widget

              1 Reply Last reply
              0
              • I Offline
                I Offline
                ich_heise_deb
                wrote on last edited by
                #8

                Hi All,

                My application architecture demands that i cannot use the overloaded changeEvent method in all the widgets...as in my application i am using Qpushbutton which does not have the changeEvent method in it....one option is to use multiple slots for the different widgets after the changeEvent emits one signal from the base mainwidget class.....On solution i have thought is to replace the Qpushbuttton with QAbstractbutton...but that can create other problems in the architecture as the App is adding QPushbutton dynamically based on the XML file parsing.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  QPushButton does have this method. All QWidget derived classes have that method.

                  I don't see why you would need to subclass QPushButton in that case. You only need to implement the changeEvent method in your complex custom widgets that will create other "base" widgets like QPushButton.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  1
                  • I Offline
                    I Offline
                    ich_heise_deb
                    wrote on last edited by
                    #10

                    Got it...but now suppose i have an Item like QStandardItem in my code which will be used to show the data in a view....but how the changeEvent shall work in the above case?

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      Do you mean you are generating QStandardItem which content is translated within your code ? If that's the case can you show how you do that ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • I Offline
                        I Offline
                        ich_heise_deb
                        wrote on last edited by
                        #12

                        Smthing like this...

                        Info->TreeItem = new QStandardItem();
                        Info->TreeItem->setText(QApplication::translate("Project Tree", Info->TreeBranch->Label->Primary) );

                        So in the above case you dont hv a changeEvent in the QStandardItem class hence will not be able to use installtranslator() in the code

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #13

                          What would the value of Primary be ? Something fixed that is translatable or a dynamic text ?

                          In any case, this is typically a situation where you implement the changeEvent method of the class where you handle the QStandardItems.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved