利用Qt.locale显示本地化数据
来源:互联网 发布:大数据用英语怎么说 编辑:程序博客网 时间:2024/05/21 17:40
我们知道对于一些应用来说,我们可以根据语言的选择来显示不同的数据格式,比如时间,金钱等。在今天的例程中,我们来展示如何Qt.locale根据不同的语言选择来帮助我们显示不同格式的数据。
import QtQuick 2.0import Ubuntu.Components 1.1/*! \brief MainView with a Label and Button elements.*/MainView { // objectName for functional testing purposes (autopilot-qt5) objectName: "mainView" // Note! applicationName needs to match the "name" field of the click manifest applicationName: "locale.liu-xiao-guo" /* This property enables the application to change orientation when the device is rotated. The default is false. */ //automaticOrientation: true // Removes the old toolbar and enables new features of the new header. useDeprecatedToolbar: false width: units.gu(60) height: units.gu(85) Page { title: i18n.tr("Locale") Rectangle { id: root anchors.fill: parent color: "lightgray" property string locale: view.currentItem.locale Text { id: title text: "Select locale:" } Rectangle { id: chooser anchors.top: title.bottom anchors.topMargin: 5 width: parent.width-10 x: 5 height: parent.height/2 - 10 color: "#40300030" ListView { id: view clip: true focus: true anchors.fill: parent model: [ "en_US", "en_GB", "fi_FI", "de_DE", "ar_SA", "hi_IN", "zh_CN", "th_TH", "fr_FR", "nb_NO", "sv_SE" ] delegate: Text { property string locale: modelData height: units.gu(3) width: view.width text: Qt.locale(modelData).name + " ("+ Qt.locale(modelData).nativeCountryName + "/" + Qt.locale(modelData).nativeLanguageName + ")" MouseArea { anchors.fill: parent onClicked: view.currentIndex = index } } highlight: Rectangle { height: 30 color: "#60300030" } } } Rectangle { color: "white" anchors.top: chooser.bottom anchors.topMargin: 5 anchors.bottom: parent.bottom anchors.bottomMargin: 5 x: 5; width: parent.width - 10 Column { anchors.fill: parent spacing: 5 Text { property var date: new Date() text: "Date: " + date.toLocaleDateString(Qt.locale(root.locale)) } Text { property var date: new Date() text: "Time: " + date.toLocaleTimeString(Qt.locale(root.locale)) } Text { property var dow: Qt.locale(root.locale).firstDayOfWeek text: "First day of week: " + Qt.locale(root.locale).standaloneDayName(dow) } Text { property var num: 10023823 text: "Number: " + num.toLocaleString(Qt.locale(root.locale)) } Text { property var num: 10023823 text: "Currency: " + num.toLocaleCurrencyString(Qt.locale(root.locale)) } } } } }}
delegate: Text { property string locale: modelData height: units.gu(3) width: view.width text: Qt.locale(modelData).name + " ("+ Qt.locale(modelData).nativeCountryName + "/" + Qt.locale(modelData).nativeLanguageName + ")" MouseArea { anchors.fill: parent onClicked: view.currentIndex = index } }
我们可以通过定义一个property locale来得到当前的Item的modelData。这样在delegate的外面,我们通过
property string locale: view.currentItem.locale
来得到当前列表项中的modelData,进而在程序的其它部分进行引用!
整个项目的源码在:https://github.com/liu-xiao-guo/locale
0 0
- 利用Qt.locale显示本地化数据
- Boost.Locale 本地化库 ...待续...
- 字符集本地化(locale)与输入法系列讲座-----(5) locale 详解
- Gentoo本地化中文设置--Locale系统介绍
- C型本地化 clocale(locale.h)
- 本地化数据
- Qt(QML)本地化
- 【Qt开发】QT中显示图像数据
- qt折线图显示数据
- qt折线图显示数据
- qt视图显示不同数据
- QT中显示图像数据
- QT中显示图像数据
- Java 本地化 Locale 资源包 PropertyResourceBundle 找不到资源包问题解决
- 利用opencv+QT打开并显示图片
- Symbian本地化显示中文
- 本地化显示错误
- 利用Reflect显示bean数据
- iOS进阶面试题----多线程
- Windows Socket 非阻塞模式开发
- android audio截取PCM数据
- ios之SEL
- Tomcat配置 无需加项目名直接访问项目
- 利用Qt.locale显示本地化数据
- TDD+结对编程活动分享
- 一种新颖创新的办公室设计风格引领时尚的潮流
- 实现一个方法,搭出最高的一堆箱子,箱堆的高度为每个箱子高度的总和
- 《C++primer(第五版)》学习之路-序
- 内存 地址 分配
- enq: TM - contention TM 等待事件的原因及模拟(表外键约束无索引导致)
- 取消文件夹拒绝访问
- 理解编译器在编译过程中做了什么