En esta página

Qt Quick Ejemplos - Canvas

Esta es una recopilación de ejemplos de QML Canvas.

Corazón rosa dibujado con curvas Bézier y controles deslizantes para el grosor de la línea, la escala, la rotación y la transparencia

Canvas es una recopilación de pequeños ejemplos de QML relacionados con el tipo Canvas. Cada ejemplo es un pequeño archivo QML que destaca un tipo o una característica concreta.

Cómo ejecutar el ejemplo

Puedes ejecutar el ejemplo desde:

Corazón rojo

«Corazón rojo » utiliza la API de curvas Bézier para trazar el contorno y rellenar un corazón rojo.

ctx.beginPath()
ctx.moveTo(75,40)
ctx.bezierCurveTo(75,37,70,25,50,25)
ctx.bezierCurveTo(20,25,20,62.5,20,62.5)
ctx.bezierCurveTo(20,80,40,102,75,120)
ctx.bezierCurveTo(110,102,130,80,130,62.5)
ctx.bezierCurveTo(130,62.5,130,25,100,25)
ctx.bezierCurveTo(85,25,75,37,75,40)
ctx.closePath()

Bocadillo

El bocadillo utiliza la API «quadraticCurveTo()» para trazar el contorno y rellenar un bocadillo personalizado:

ctx.beginPath()
ctx.moveTo(75, 25)
ctx.quadraticCurveTo(25, 25, 25, 62.5)
ctx.quadraticCurveTo(25, 100, 50, 100)
ctx.quadraticCurveTo(50, 120, 30, 125)
ctx.quadraticCurveTo(60, 120, 65, 100)
ctx.quadraticCurveTo(125, 100, 125, 62.5)
ctx.quadraticCurveTo(125, 25, 75, 25)
ctx.closePath()

Este ejemplo también muestra cómo se utiliza la API fillText():

ctx.fillStyle = "white"
ctx.font = "bold 17px sans-serif"
ctx.fillText("Qt Quick", 40, 70)

Squircle

«Squircle» utiliza un conjunto de API de trazado sencillas, como `moveTo()` y `lineTo()`, para dibujar un «squircle» con contornos suaves.

Rectángulo redondeado

El rectángulo redondeado utiliza un conjunto de API de trazado lineTo() y arcTo() para dibujar un rectángulo redondeado.

Cara sonriente

Cara sonriente utiliza varias rutas para dibujar y rellenar una cara sonriente.

Recorte

Recorte utiliza la API clip para recortar una imagen determinada.

ctx.clip()
ctx.drawImage(canvas.imagefile, 0, 0)

Tigre

«Tigre» utiliza la API de trazados SVG para dibujar un tigre mediante una serie de cadenas de trazados SVG.

for (let i = 0; i < Tiger.tiger.length; i++) {
    if (Tiger.tiger[i].width !== undefined)
        ctx.lineWidth = Tiger.tiger[i].width

    if (Tiger.tiger[i].path !== undefined)
        ctx.path = Tiger.tiger[i].path

    if (Tiger.tiger[i].fill !== undefined) {
        ctx.fillStyle = Tiger.tiger[i].fill
        ctx.fill()
    }

    if (Tiger.tiger[i].stroke !== undefined) {
        ctx.strokeStyle = Tiger.tiger[i].stroke
        ctx.stroke()
    }
}

Proyecto de ejemplo en code.qt.io

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