이 페이지에서

텍스트 표시

텍스트를 표시하기 위해 Qt Quick 모듈에서 ‘Text’ 유형이 제공됩니다. 관련 용도로는 ‘ TextInput ’ 및 ‘ TextEdit ’ 유형이 편집 가능한 텍스트 컨트롤을 제공합니다. 완전한 HTML 마크업을 사용하려면 ‘ Qt WebEngine ’ 모듈을 참조하십시오.

텍스트 표시 및 서식 지정

QML에서 텍스트를 표시하려면 Text 항목을 생성하고 text 속성을 표시하려는 텍스트로 설정하십시오. 그러면 Text 항목에 해당 텍스트가 표시됩니다.

Text 항목에는 전체 텍스트 블록의 서식을 지정하기 위해 여러 속성을 설정할 수 있습니다. 여기에는 색상, 글꼴 가족, 글꼴 크기, 굵게 및 기울임꼴이 포함됩니다. 속성의 전체 목록은 Text 타입 문서를 참조하십시오.

Text 항목을 사용하여 마크업과 같은 리치 텍스트를 통해 텍스트의 특정 부분을 선택적으로 서식 지정할 수 있습니다. 이 기능을 사용하려면 ` Text::textFormat `을 `Text.StyledText`로 설정하십시오. 자세한 내용은 ` Text ` 타입의 문서에서 확인할 수 있습니다.

텍스트 레이아웃 지정

기본적으로 Text는 텍스트에 줄바꿈 문자가 포함되어 있지 않은 한 텍스트를 한 줄로 표시합니다. 줄 바꿈을 하려면 wrapMode 속성을 설정하고 텍스트가 줄 바꿈될 수 있도록 명시적인 너비를 지정하십시오. 너비나 높이가 명시적으로 설정되지 않은 경우, 해당 속성을 읽으면 텍스트의 경계 사각형 매개변수가 반환됩니다(너비나 높이를 명시적으로 설정한 경우에도 paintedWidth 및 paintedHeight를 계속 사용할 수 있습니다). 이러한 매개변수를 고려하여 Text는 다른 Item과 마찬가지로 배치할 수 있습니다.

예제 코드

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
        }
    }
}

제목, 본문, 기울임꼴 등 다양한 서식으로 표시된 텍스트

국제화 및 확장성

텍스트를 다룰 때 애플리케이션은 기기의 방향 및 언어 설정과 같은 다양한 요소를 고려해야 합니다.

다음 페이지에서는 이러한 다양한 주제에 대해 자세히 설명합니다.

© 2026 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.