Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Solved Translation Problem for retranslateUi function

    General and Desktop
    3
    8
    3429
    Loading More Posts
    • 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.
    • C
      cdcc0606 last edited by

      I'm use the fonction QDesktopServices::openUrl(QUrl::fromLocalFile(repertoire_DocAide));

      C 1 Reply Last reply Reply Quote 0
      • C
        cdcc0606 @cdcc0606 last edited by

        My problem is when I use this function retranslateUI, it can translate the sentence. However, when it turns to a header of Qtableview, it didn't translate. I don't know why. Do I need something special to translate for the Qtableview Header?

        1 Reply Last reply Reply Quote 0
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          Hi and welcome to devnet,

          Are you setting the QTableView header content by hand ?

          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 Reply Quote 0
          • C
            cdcc0606 last edited by

            Yes. It's set as following:
            model=new QStandardItemModel(0,6,this);
            model->setHorizontalHeaderItem(0, new QStandardItem(tr("Name")));
            model->setHorizontalHeaderItem(1, new QStandardItem(tr("I/O")));
            model->setHorizontalHeaderItem(2, new QStandardItem(tr("State")));
            model->setHorizontalHeaderItem(3, new QStandardItem(tr("Duration")));
            model->setHorizontalHeaderItem(4, new QStandardItem(tr("Date")));

            1 Reply Last reply Reply Quote 0
            • SGaist
              SGaist Lifetime Qt Champion last edited by

              Then you have to rewrite your code a bit. See the dynamic translation part of the internationalization documentation.

              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 Reply Quote 0
              • C
                cdcc0606 last edited by

                Yes, then I use lupdate and Irelease. Then I translate all the word in tr() to another language in Qt Linguist one by one. All the other words can be translated except for the words of five lines in the above. So i don't know why

                mrjj 1 Reply Last reply Reply Quote 0
                • mrjj
                  mrjj Lifetime Qt Champion @cdcc0606 last edited by mrjj

                  @cdcc0606
                  Hmm, and you do load this translator BEFORE u add items to
                  the header ?

                  There is no magic going so you need to re-add the items if already added.
                  as @SGaist mentions
                  http://doc.qt.io/qt-5/internationalization.html#dynamic-translation
                  look at the
                  void MyWidget::changeEvent(QEvent *event)
                  it sets the texts again.
                  like
                  okPushButton->setText(tr("&OK"));

                  This is needed if u change language WHILE the app is up and running.

                  Alternatively, just delete model and create again using same function if that an option.

                  1 Reply Last reply Reply Quote 0
                  • C
                    cdcc0606 last edited by

                    Yeah, you are right. I did as you sais, it works, Thanks.

                    1 Reply Last reply Reply Quote 1
                    • First post
                      Last post