Qt Quick Ejemplos: efectos de sombreado
Un ejemplo de Qt Quick que muestra el uso de efectos de sombreador.

Este ejemplo muestra algunos efectos visuales que se pueden crear con los sombreadores en Qt Quick. Aplica cinco efectos diferentes a un texto y a un par de imágenes. Para obtener más información, visita «Conceptos importantes en Qt Quick » - Graphical Effects
Ejecución del ejemplo
Puede ejecutar el ejemplo desde:
- Qt Creator
Abre el modo « Welcome » y selecciona el ejemplo en Examples. Para obtener más información, consulta Qt Creator: Tutorial: Compilar y ejecutar.
- Qt Extension for Visual Studio Code
Ejecute el comando « Qt: Open Qt examples » desde Command Palette y seleccione el ejemplo de la lista. Para obtener más información, consulte Qt Extension for Visual Studio Code: Tutorial: Compilar y ejecutar.
Uso de ShaderEffect
El tipo ` ShaderEffect ` suele operar sobre otros tipos, utilizando un ` ShaderEffectSource`:
ShaderEffectSource {
id: theSource
sourceItem: theItem
}En el fragmento de código anterior, ` theItem ` es el identificador de un objeto QML complejo del archivo.
Los ShaderEffects pueden utilizar este ShaderEffectSource como textura en su fragment shader:
fragmentShader: "content/shaders/wobble.frag.qsb"Para admitir múltiples API gráficas, no solo OpenGL, el código fuente del sombreador no está incrustado en QML. El archivo .qsb al que se hace referencia es un paquete de sombreadores pregenerado que contiene múltiples variantes del código del sombreador. Qt Quick selecciona el shader adecuado en tiempo de ejecución, en función de la API gráfica (Vulkan, Metal, Direct3D 11 u OpenGL) utilizada en ese momento. El archivo .qsb se genera fuera de línea y se incluye con el ejecutable a través del sistema de recursos de Qt.
Puedes utilizar cualquier propiedad personalizada de ShaderEffect en tu sombreador. Esto facilita mucho la creación de código de sombreador animado:
property variant source: theSource
property real bend
property real minimize
property real side: genieSlider.value
SequentialAnimation on bend {
loops: Animation.Infinite
NumberAnimation { to: 1; duration: 700; easing.type: Easing.InOutSine }
PauseAnimation { duration: 1600 }
NumberAnimation { to: 0; duration: 700; easing.type: Easing.InOutSine }
PauseAnimation { duration: 1000 }
}
SequentialAnimation on minimize {
loops: Animation.Infinite
PauseAnimation { duration: 300 }
NumberAnimation { to: 1; duration: 700; easing.type: Easing.InOutSine }
PauseAnimation { duration: 1000 }
NumberAnimation { to: 0; duration: 700; easing.type: Easing.InOutSine }
PauseAnimation { duration: 1300 }
}ShaderEffects también puede tener un sombreador de vértices personalizado. Al establecer la propiedad «mesh» en ShaderEffect, se proporcionan más vértices para manipular, lo que permite crear más efectos.
mesh: Qt.size(10, 10)
vertexShader: "content/shaders/genie.vert.qsb"© 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.