I am trying to make an app with live translation of text in a large tree model menu structure, in the same manner as: https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/itemviews/simpletreemodel?h=5.15
The item's "data" is a QString that is translated like
root = new MenuObject(tr("Main menu"));
And children are appended like:
root->appendChild(new MenuObject(tr("Test 1")))
.appendChild(new MenuObject(tr("Test 2")))
I am using QML to show these, with a qmllistpoprerty to show these menus like:
Q_PROPERTY(QQmlListProperty<MenuObject> list READ getList NOTIFY listChanged);
The QML is a simple ListView with a delegate Label showing the MenuObjects's description with the q_property:
Q_PROPERTY(QString description READ getDescription CONSTANT);
To change language i am using a function getting the translation file into the translator, followed by:
installTranslator(translator);
engine.retranslate();
Now this does work for simple q_properties like:
Q_PROPERTY(QString header READ getHeader NOTIFY listChanged);
Where
QString MainMenu::getHeader(){
return tr("Header");
}
But I CANNOT get the translations to work for the items in the treemodel. Any help is appreciated.