如何在QML应用中显示在系统中的所有的字体
来源:互联网 发布:Java的官网 编辑:程序博客网 时间:2024/05/16 12:09
在这篇文章中,我们来显示在Ubuntu 手机中所有的已经有的字体.大家可以根据自己的需求来选择自己所需要的字体.我们已经在先前的文章" 如何在QML中使用不同的字体(font)"已经展示了如何使用font来显示不同的字体.
我们可以通过如下的方式来显示所有的字体:
AvailableFonts.qml
import QtQuick 2.0import Ubuntu.Components 1.1Rectangle { color: "steelblue" property int size: 60 ListView { clip: true anchors.fill: parent model: Qt.fontFamilies() delegate: Item { height: units.gu(4) width: ListView.view.width Row { height: parent.height width: parent.width Text { anchors.verticalCenter: parent.verticalCenter text: "I love you!" width: units.gu(25) font { family: modelData; pixelSize: size } } Text { anchors.verticalCenter: parent.verticalCenter text: modelData color: "white" } } Rectangle { color: "red" height: 2 width: parent.width } } }}
Main.qml
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: "fontlist.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("Font list") Text { id: txt anchors.top: parent.top anchors.horizontalCenter: parent.horizontalCenter text: "我爱你 " + font.family + " " + font.pixelSize height: units.gu(3) } AvailableFonts { anchors.fill: parent anchors.topMargin:txt.height } }}
运行我们的应用:
所有的源码在: https://github.com/liu-xiao-guo/fontlist
0 0
- 如何在QML应用中显示在系统中的所有的字体
- 如何在QML应用中调用系统设置中的页面来设置我们的系统
- 如何在QML中使用不同的字体(font)
- 如何在QML应用中得到一个Item的所有属性,信号及方法
- 在QML应用中显示image tag
- 如何在QML应用中读写文件
- 如何在QML应用中启动Scope
- 如何在QML应用中设计自己的Dialog
- 如何在Ubuntu QML应用中实现ComboBox的功能
- 如何在QML应用中创建类似ContextMenu的控件
- 如何在QML应用中在触屏的时候感知触觉
- 如何在QML应用中动态修改ListModel中的数据并存储它为JSON格式
- Android4.2 使preinstall中的所有应用正常显示在launcher的默认布局中
- Android4.2 使preinstall中的所有应用正常显示在launcher的默认布局中
- 如何优化在Ubuntu手机中的QML应用
- 如何在Ubuntu QML应用中判断应用的方位(landscape或portrait)
- 如何在Ubuntu QML应用中使用Push Notification
- 如何在QML应用中使用Javascript解析JSON
- 抽象类151219AbstractDemo
- 如何调用百度编辑器ueditor的上传图片、上传文件
- 欢迎使用CSDN-markdown编辑器
- 一份互联网从业者及创业者必读的书单
- 151219InterfaceDemo
- 如何在QML应用中显示在系统中的所有的字体
- Android抽象布局——include、merge、ViewStub
- Android:网络:网页源码查看器
- 消息机制
- 如何优化代码实例151219TemplateDemo
- 一个ip一个阿里云服务器配置多个网站之Apache配置
- 覆盖上一个Activity右滑退出功能小米手机看见桌面或者背景黑屏不透明问题
- 一个ip一个阿里云服务器配置多个网站之具体步骤
- Openstack的消息队列机制及其部分代码解析(非oslo.message)