当前位置: 首页 > news >正文

QML Text详解

1.简介

文本项可以显示普通文本和富文本。

2.示例

示例1:一个简单的text,可以设置字体颜色、大小等。

Window {visible: truewidth: 400height: 400title: qsTr("Hello World")Rectangle{width: 200height: 200border.width: 2Text {text: "Hello World!"font.family: "Helvetica"font.bold: truefont.italic: truefont.underline: truefont.pointSize: 24color: "red"}}
}

示例2:设置字体过长用省略号显示。

elide:设置此属性以消除适合于Text项目宽度的文本部分。仅当设置了显式宽度时,文本才会消失。此属性不能与富文本一起使用

  • Text.ElideNone(默认):不缩略;
  • Text.ElideLeft:文本左端缩略;
  • Text.ElideMiddle:文本中间缩略;
  • Text.ElideRight:文本右端缩略;

Window {visible: truewidth: 400height: 400title: qsTr("Hello World")Rectangle{width: 200height: 200border.width: 2Text {text: "Hello World! Hello World! Hello World!"font.family: "Helvetica"font.bold: truefont.italic: truefont.underline: truefont.pointSize: 24color: "red"anchors.fill: parentelide: Text.ElideRight}}
}

示例3:设置额外的文本样式。

Window {visible: truewidth: 400height: 400title: qsTr("Hello World")Row {Text { font.pointSize: 24; text: "Normal" }Text { font.pointSize: 24; text: "Raised"; style: Text.Raised; styleColor: "#AAAAAA" }Text { font.pointSize: 24; text: "Outline";style: Text.Outline; styleColor: "red" }Text { font.pointSize: 24; text: "Sunken"; style: Text.Sunken; styleColor: "#AAAAAA" }}}

示例4:设置富文本。

Window {visible: truewidth: 400height: 400title: qsTr("Hello World")Column {Text {font.pointSize: 24text: "<b>Hello</b> <i>World!</i>"}Text {font.pointSize: 24textFormat: Text.RichTexttext: "<b>Hello</b> <i>World!</i>"}Text {font.pointSize: 24textFormat: Text.PlainTexttext: "<b>Hello</b> <i>World!</i>"}}}

示例5:设置行高,自动换行。

wrapMode属性:Text控件文本换行属性。仅当设置了显式宽度时,文本才会换行。

  • Text.NoWrap(默认):不执行换行。如果文本宽度大于控件的width,则文本无法显示完全。
  • Text.WordWrap:换行仅在单词边界上完成。如果单词太长,单词会无法显示完全。
  • Text.WrapAnywhere:可以在任意一处位置换行,即使是单词的中间。
  • Text.Wrap:如果可能的话,在单词边界处换行;否则,它将出现在行中的适当点,即使是在单词中间。

lineHeight属性:设置文本的行距。具体取决于lineHeightMode。默认值为1.0的倍数,行距必须为正值。

Window {visible: truewidth: 400height: 400title: qsTr("Hello World")Rectangle{width: 200height: 200border.width: 2Text {text: "Hello World! Hello World! Hello World!"font.family: "Helvetica"font.bold: truefont.italic: truefont.underline: truefont.pointSize: 24color: "red"anchors.fill: parentwrapMode: Text.WordWrap//lineHeightMode:Text.FixedHeightlineHeight: 2}}
}

 

http://www.lryc.cn/news/32237.html

相关文章:

  • xxl-job启用https访问
  • 2023FL Studio最新中文版电子音乐、混音和母带制作DAW
  • pytorch 35 yolov5_obb项目解读+使用技巧+调优经验(提升map)
  • OpenMv H7 口罩识别--毕业设计学习记录
  • 有什么比较好的bug管理工具?5款热门工具推荐
  • 第五章 opengl之摄像机
  • nginx配置详解(容器、负载)—官方原版
  • 2023年中职网络安全竞赛——CMS网站渗透解析
  • SQL 窗口函数详解
  • Android 12系统源码_SystemUI(六)显示和隐藏最近任务
  • Docekr三剑客之 Docekr compose
  • 企业是否具备等保测评资质在哪里查?怎么查?
  • Spacedesk软件推荐,让你的平板也变成电脑的副屏
  • Vue 3.0 组合式API 介绍 【Vue3 从零开始】
  • 【算法数据结构体系篇class13、14】:贪心算法思想
  • C++知识点,关键字inline ,String,强制类型转化
  • MyBatis源码分析(六)MetaObject工具类的使用与源码分析
  • 文献资源最多的文献下载神器,99.99%的文献都可下载
  • 工控机ARM工业边缘计算机搭建Node-Red环境
  • 位图/布隆过滤器/海量数据处理方式
  • Tomcat 配置文件数据库密码加密
  • k8s-Kubernetes集群部署
  • Python数据分析案例19——上市银行财务指标对比
  • Python 中错误 ConnectionError: Max retries exceeded with url
  • SpringBoot下的Spring框架学习(Tedu)——DAY02
  • 容易混淆的点:C语言中char* a[] 与 char a[] 的区别以及各自的用法
  • 认识Spring(下)
  • Educational Codeforces Round 144 (Rated for Div. 2) C - Maximum Set
  • 学python的第四天---基础(2)
  • spring之refresh流程-Java八股面试(六)