翻譯|使用教程|編輯:龔雪|2021-12-17 09:58:05.880|閱讀 249 次
概述:本文主要介紹如何在QML中顯示文本,歡迎下載框架產品體驗~
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
要在QML中顯示文本,請創建一個Text項并將text屬性設置為您希望顯示的文本,Text項現在將顯示該文本。
可以在Text項目上設置幾個屬性來設置整個文本塊的樣式,這些包括顏色、字體系列、字體大小、粗體和斜體。
富文本(如標記)可用于使用Text項選擇性地設置文本特定部分的樣式,將 Text::textFormat 設置為 Text.StyledText來使用此功能。
默認情況下,除非文本包含嵌入的換行符,否則會將文本顯示為單行。要換行,請設置 wrapMode 屬性并為文本提供明確的換行寬度。 如果沒有明確設置寬度或高度,讀取這些屬性將返回文本邊界矩形的參數(如果您已經明確設置寬度或高度,仍然可以使用paintedWidth和paintedHeight)。考慮到這些參數,文本可以像任何其他項目一樣定位。
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 } } }
在處理文本時,應用程序必須考慮各種主題,例如設備的方向和語言設置。
Qt技術交流群:166830288 歡迎一起進群討論
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都網