Translation Problem for retranslateUi function
-
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=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.
-
@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.