En esta página

Visualización de texto

Para mostrar texto, el módulo Qt Quick módulo. Para usos relacionados, los tipos « TextInput » y « TextEdit » proporcionan controles de texto editables. Para el marcado HTML completo, consulta el módulo « Qt WebEngine ».

Visualización y formato del texto

Para mostrar texto en QML, crea un elemento «Text» y establece la propiedad «text» con el texto que desees mostrar. El elemento «Text» mostrará ahora ese texto.

Se pueden establecer varias propiedades en el elemento Text para aplicar estilo a todo el bloque de texto. Entre ellas se incluyen el color, la familia de fuentes, el tamaño de fuente, la negrita y la cursiva. Para obtener una lista completa de propiedades, consulta la documentación del tipo Text.

Se puede utilizar texto enriquecido, como el marcado, para aplicar estilos de forma selectiva a secciones específicas de texto con un elemento «Text». Establece « Text::textFormat » en «Text.StyledText» para utilizar esta funcionalidad. Encontrarás más detalles en la documentación del tipo « Text ».

Maquetación del texto

De forma predeterminada, Text mostrará el texto en una sola línea, a menos que contenga saltos de línea incrustados. Para que el texto se ajuste a la línea, configura la propiedad wrapMode y asigna al texto un ancho explícito al que se ajuste. Si el ancho o la altura no se han establecido explícitamente, al leer estas propiedades se devolverán los parámetros del rectángulo delimitador del texto (si has establecido explícitamente el ancho o la altura, puedes seguir utilizando paintedWidth y paintedHeight). Teniendo en cuenta estos parámetros, el Text se puede colocar como cualquier otro Item.

Código de ejemplo

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

Texto mostrado en distintos estilos, como título, cuerpo e itálica

Internacionalización y escalabilidad

Al trabajar con textos, las aplicaciones deben tener en cuenta diversos aspectos, como la orientación del dispositivo y la configuración de idioma.

En las páginas siguientes se tratan en detalle estos diversos aspectos.

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