QML官方系列教程——Use Case - Displaying Text In QML

2024-06-06 00:38

本文主要是介绍QML官方系列教程——Use Case - Displaying Text In QML,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

附网址:http://qt-project.org/doc/qt-5/qtquick-usecase-text.html


Displaying and Formatting Text—— 显示并设置文本格式

要想在QML中显示文本,只需要创建一个Text对象并在它的text属性中设置你希望显示的文本,这样它就可以显示你的文本了。

Text对象有多个用来修改文本风格的属性值。其中包含颜色、字体库、字体大小、加粗以及斜体。查看Text类型文档来了解全部的属性。

使用富文本的标记来选择性地更改一个文本对象中的部分内容的风格。将Text::textFormat设置为Text.StyledText中来使用这个功能(译者注:相比于Text.RichText,Text.StyledText只支持部分常用的HTML标签,但QML对其进行了优化以获得更佳的表现性能,因此Qt更推荐使用Text.StyledText)。到Text类型的文档来了解更多有关细节。


Laying out Text —— 文本编排

默认情况下,Text以单行显示文本,除非它内部包含多行内容。为了设置文本的换行方式,需要设置wrapMode属性,并为文本设定一个明确的宽度。如果宽度和高度没有被显式地设置,读取这些参数时将返回这个文本所绑定的矩形框的尺寸(如果你已经显式设置了宽高,你依然可以使用paintedWidth和paintedHeight)。记住了这些参数,Text就可以像任何其他Item一样被定位。


Example Code —— 示例代码

import QtQuick 2.0Item {id: rootwidth: 480height: 320Rectangle {color: "#272822"width: 480height: 320}Column {spacing: 20Text {text: 'I am the very model of a modern major general!'// color can be set on the entire element with this propertycolor: "yellow"}Text {// For text to wrap, a width has to be explicitly providedwidth: root.width// This setting makes the text wrap at word boundaries when it goes past the width of the Text objectwrapMode: Text.WordWrap// You can use \ to escape quotation marks, or to add new lines (\n). Use \\ to get a \ in the stringtext: 'I am the very model of a modern major general. I\'ve information vegetable, animal and mineral. I know the kings of england and I quote the fights historical; from Marathon to Waterloo in order categorical.'// color can be set on the entire element with this propertycolor: "white"}Text {text: 'I am the very model of a modern major general!'// color can be set on the entire element with this propertycolor: "yellow"// font properties can be set effciently on the whole string at oncefont { family: 'Courier'; pixelSize: 20; italic: true; capitalization: Font.SmallCaps }}Text {// HTML like markup can also be usedtext: '<font color="white">I am the <b>very</b> model of a modern <i>major general</i>!</font>'// This could also be written font { pointSize: 14 }. Both syntaxes are valid.font.pointSize: 14// StyledText format supports fewer tags, but is more efficient than RichTexttextFormat: Text.StyledText}}
}

·


这篇关于QML官方系列教程——Use Case - Displaying Text In QML的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1034626

相关文章

Spring Security 从入门到进阶系列教程

Spring Security 入门系列 《保护 Web 应用的安全》 《Spring-Security-入门(一):登录与退出》 《Spring-Security-入门(二):基于数据库验证》 《Spring-Security-入门(三):密码加密》 《Spring-Security-入门(四):自定义-Filter》 《Spring-Security-入门(五):在 Sprin

Makefile简明使用教程

文章目录 规则makefile文件的基本语法:加在命令前的特殊符号:.PHONY伪目标: Makefilev1 直观写法v2 加上中间过程v3 伪目标v4 变量 make 选项-f-n-C Make 是一种流行的构建工具,常用于将源代码转换成可执行文件或者其他形式的输出文件(如库文件、文档等)。Make 可以自动化地执行编译、链接等一系列操作。 规则 makefile文件

活用c4d官方开发文档查询代码

当你问AI助手比如豆包,如何用python禁止掉xpresso标签时候,它会提示到 这时候要用到两个东西。https://developers.maxon.net/论坛搜索和开发文档 比如这里我就在官方找到正确的id描述 然后我就把参数标签换过来

科研绘图系列:R语言扩展物种堆积图(Extended Stacked Barplot)

介绍 R语言的扩展物种堆积图是一种数据可视化工具,它不仅展示了物种的堆积结果,还整合了不同样本分组之间的差异性分析结果。这种图形表示方法能够直观地比较不同物种在各个分组中的显著性差异,为研究者提供了一种有效的数据解读方式。 加载R包 knitr::opts_chunk$set(warning = F, message = F)library(tidyverse)library(phyl

【生成模型系列(初级)】嵌入(Embedding)方程——自然语言处理的数学灵魂【通俗理解】

【通俗理解】嵌入(Embedding)方程——自然语言处理的数学灵魂 关键词提炼 #嵌入方程 #自然语言处理 #词向量 #机器学习 #神经网络 #向量空间模型 #Siri #Google翻译 #AlexNet 第一节:嵌入方程的类比与核心概念【尽可能通俗】 嵌入方程可以被看作是自然语言处理中的“翻译机”,它将文本中的单词或短语转换成计算机能够理解的数学形式,即向量。 正如翻译机将一种语言

SWAP作物生长模型安装教程、数据制备、敏感性分析、气候变化影响、R模型敏感性分析与贝叶斯优化、Fortran源代码分析、气候数据降尺度与变化影响分析

查看原文>>>全流程SWAP农业模型数据制备、敏感性分析及气候变化影响实践技术应用 SWAP模型是由荷兰瓦赫宁根大学开发的先进农作物模型,它综合考虑了土壤-水分-大气以及植被间的相互作用;是一种描述作物生长过程的一种机理性作物生长模型。它不但运用Richard方程,使其能够精确的模拟土壤中水分的运动,而且耦合了WOFOST作物模型使作物的生长描述更为科学。 本文让更多的科研人员和农业工作者

flume系列之:查看flume系统日志、查看统计flume日志类型、查看flume日志

遍历指定目录下多个文件查找指定内容 服务器系统日志会记录flume相关日志 cat /var/log/messages |grep -i oom 查找系统日志中关于flume的指定日志 import osdef search_string_in_files(directory, search_string):count = 0

沁恒CH32在MounRiver Studio上环境配置以及使用详细教程

目录 1.  RISC-V简介 2.  CPU架构现状 3.  MounRiver Studio软件下载 4.  MounRiver Studio软件安装 5.  MounRiver Studio软件介绍 6.  创建工程 7.  编译代码 1.  RISC-V简介         RISC就是精简指令集计算机(Reduced Instruction SetCom

前端技术(七)——less 教程

一、less简介 1. less是什么? less是一种动态样式语言,属于css预处理器的范畴,它扩展了CSS语言,增加了变量、Mixin、函数等特性,使CSS 更易维护和扩展LESS 既可以在 客户端 上运行 ,也可以借助Node.js在服务端运行。 less的中文官网:https://lesscss.cn/ 2. less编译工具 koala 官网 http://koala-app.

GPT系列之:GPT-1,GPT-2,GPT-3详细解读

一、GPT1 论文:Improving Language Understanding by Generative Pre-Training 链接:https://cdn.openai.com/research-covers/languageunsupervised/language_understanding_paper.pdf 启发点:生成loss和微调loss同时作用,让下游任务来适应预训