Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Translation Problem for retranslateUi function
I'm use the fonction QDesktopServices::openUrl(QUrl::fromLocalFile(repertoire_DocAide));
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?
Hi and welcome to devnet,
Are you setting the QTableView header content by hand ?
Yes. It's set as following:
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")));
Then you have to rewrite your code a bit. See the dynamic translation part of the internationalization documentation.
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
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
look at the
void MyWidget::changeEvent(QEvent *event)
it sets the texts again.
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.
Yeah, you are right. I did as you sais, it works, Thanks.