사용 사례 - QML에서 텍스트 표시
텍스트 표시 및 서식 지정하기
QML에 텍스트를 표시하려면 텍스트 항목을 만들고 텍스트 속성을 표시하려는 텍스트로 설정합니다. 이제 텍스트 항목에 해당 텍스트가 표시됩니다.
텍스트 항목에 여러 속성을 설정하여 전체 텍스트 블록의 스타일을 지정할 수 있습니다. 여기에는 색상, 글꼴 모음, 글꼴 크기, 굵게 및 이탤릭체 등이 포함됩니다. 전체 속성 목록은 Text 유형 문서를 참조하세요.
마크업과 같은 서식 있는 텍스트를 사용하여 텍스트 항목으로 텍스트의 특정 섹션에 선택적으로 스타일을 지정할 수 있습니다. 이 기능을 사용하려면 Text::textFormat 을 Text.StyledText로 설정하세요. 자세한 내용은 Text 유형 문서에서 확인할 수 있습니다.
텍스트 레이아웃
기본적으로 텍스트는 포함 된 줄 바꿈이 포함되지 않는 한 텍스트를 한 줄로 표시합니다. 줄을 줄바꿈하려면 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 } } }
국제화 및 확장성
텍스트를 다룰 때 애플리케이션은 기기의 방향 및 언어 설정과 같은 다양한 주제를 고려해야 합니다.
다음 페이지에서는 이러한 다양한 주제에 대해 자세히 설명합니다.
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.