翻譯|使用教程|編輯:龔雪|2021-12-17 09:58:05.880|閱讀 249 次
概述:本文主要介紹如何在QML中顯示文本,歡迎下載框架產(chǎn)品體驗(yàn)~
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
相關(guān)鏈接:
要在QML中顯示文本,請(qǐng)創(chuàng)建一個(gè)Text項(xiàng)并將text屬性設(shè)置為您希望顯示的文本,Text項(xiàng)現(xiàn)在將顯示該文本。
可以在Text項(xiàng)目上設(shè)置幾個(gè)屬性來(lái)設(shè)置整個(gè)文本塊的樣式,這些包括顏色、字體系列、字體大小、粗體和斜體。
富文本(如標(biāo)記)可用于使用Text項(xiàng)選擇性地設(shè)置文本特定部分的樣式,將 Text::textFormat 設(shè)置為 Text.StyledText來(lái)使用此功能。
默認(rèn)情況下,除非文本包含嵌入的換行符,否則會(huì)將文本顯示為單行。要換行,請(qǐng)?jiān)O(shè)置 wrapMode 屬性并為文本提供明確的換行寬度。 如果沒(méi)有明確設(shè)置寬度或高度,讀取這些屬性將返回文本邊界矩形的參數(shù)(如果您已經(jīng)明確設(shè)置寬度或高度,仍然可以使用paintedWidth和paintedHeight)。考慮到這些參數(shù),文本可以像任何其他項(xiàng)目一樣定位。
import QtQuick Item { id: root width: 480 height: 320 Rectangle { color: "#272822" width: 480 height: 320 } Column { spacing: 20 Text { text: 'I am the very model of a modern major general!' // color can be set on the entire element with this property color: "yellow" } Text { // For text to wrap, a width has to be explicitly provided width: root.width // This setting makes the text wrap at word boundaries when it goes // past the width of the Text object wrapMode: Text.WordWrap // You can use \ to escape quotation marks, or to add new lines (\n). // Use \\ to get a \ in the string text: '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 property color: "white" } Text { text: 'I am the very model of a modern major general!' // color can be set on the entire element with this property color: "yellow" // font properties can be set effciently on the whole string at once font { family: 'Courier'; pixelSize: 20; italic: true; capitalization: Font.SmallCaps } } Text { // HTML like markup can also be used text: '<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 RichText textFormat: Text.StyledText } } }
在處理文本時(shí),應(yīng)用程序必須考慮各種主題,例如設(shè)備的方向和語(yǔ)言設(shè)置。
Qt技術(shù)交流群:166830288 歡迎一起進(jìn)群討論
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都網(wǎng)