如何在qml ListModel 里国际化文字
翻译qml里的文字是,一般使用的 qsTr(),
但是如果在ListModel 里用,
比如:
ListModel { ListElement { title: qsTr( "Calendar" ) ; iconSource: "icons/calendar.png" }
则会报错
ListElement: cannot use script for property value
解决方案:
import QtQuick 1.0 ListModel { ListElement { iconSource: "icons/calendar.png" } ListElement { iconSource: "icons/develop.png" } ListElement { iconSource: "icons/globe.png" } ListElement { iconSource: "icons/mail.png" } ListElement { iconSource: "icons/music.png" } ListElement { iconSource: "icons/phone.png" } function title( index) { if ( title[ "text" ] === undefined) { title.text = [ qsTr( "Calendar" ) , qsTr( "Setup" ) , qsTr( "Internet" ) , qsTr( "Messages" ) , qsTr( "Music" ) , qsTr( "Call" ) ] } return title.text [ index] } }
然后在listview里设置
text: view.model.title(view.currentIndex)
相关推荐
Chenliaoyuan 2020-06-11
moyigg 2020-04-20
Chenliaoyuan 2020-04-14
Donven 2019-09-07
startXUEBA 2018-03-24
88971730 2011-08-18
jackiebobo 2011-04-08
ccgsteel 2019-06-30
aSuncat 2018-03-24
<div class="panel-body" style="height: 300px; width: 100%; overflow: auto;" data-platform-scroll="&q
道北吴彦祖 2017-01-15
乔乔 2016-07-20
goodyatou 2016-03-27
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="icons/apple-touch-icon-114x114-precom
道北吴彦祖 2015-09-29
Pig00 2019-06-27