Translation Problem for retranslateUi function
-
Hi and welcome to devnet,
Are you setting the QTableView header content by hand ?
-
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"))); -
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
@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.