Qt Quick Exemplos - Animação
Esta é uma coleção de exemplos de animação em QML.

A seção“Animação” reúne pequenos exemplos em QML relacionados a animações. Cada exemplo é um pequeno arquivo QML que destaca um tipo ou recurso específico.
Para obter mais informações sobre animações, acesse Conceitos importantes em Qt Quick — Estados, Transições e Animações.
Executando o exemplo
Você pode executar o exemplo da seguinte forma:
- Qt Creator
Abra o modo “ Welcome ” e selecione o exemplo em “ Examples ”. Para obter mais informações, consulte “Qt Creator ”: Tutorial: Compilar e executar.
- Qt Extension for Visual Studio Code
Execute o comando “ Qt: Open Qt examples ” na janela “ Command Palette ” e selecione o exemplo na lista. Para mais informações, consulte Qt Extension for Visual Studio Code: Tutorial: Compilar e executar.
ColorAnimation
O ColorAnimation usa animações de cor para fazer o céu passar do dia para a noite.
gradient: Gradient {
GradientStop {
position: 0.0
SequentialAnimation on color {
loops: Animation.Infinite
ColorAnimation { from: "#14148c"; to: "#0E1533"; duration: 5000 }
ColorAnimation { from: "#0E1533"; to: "#14148c"; duration: 5000 }
}
}
GradientStop {
position: 1.0
SequentialAnimation on color {
loops: Animation.Infinite
ColorAnimation { from: "#14aaff"; to: "#437284"; duration: 5000 }
ColorAnimation { from: "#437284"; to: "#14aaff"; duration: 5000 }
}
}
}PropertyAnimation
O PropertyAnimation usa animações numéricas para fazer um círculo saltar para cima e para baixo.
// Animate the y property. Setting loops to Animation.Infinite makes the
// animation repeat indefinitely, otherwise it would only run once.
SequentialAnimation on y {
loops: Animation.Infinite
// Move from minHeight to maxHeight in 300ms, using the OutExpo easing function
NumberAnimation {
from: smiley.minHeight; to: smiley.maxHeight
easing.type: Easing.OutExpo; duration: 300
}
// Then move back to minHeight in 1 second, using the OutBounce easing function
NumberAnimation {
from: smiley.maxHeight; to: smiley.minHeight
easing.type: Easing.OutBounce; duration: 1000
}
// Then pause for 500ms
PauseAnimation { duration: 500 }
}Animators
O Animators usa animadores para fazer um ícone pular para cima e para baixo.
SequentialAnimation {
SequentialAnimation {
ParallelAnimation {
YAnimator {
target: smiley;
from: smiley.minHeight;
to: smiley.maxHeight
easing.type: Easing.OutExpo;
duration: 300
}
ScaleAnimator {
target: shadow
from: 1
to: 0.5
easing.type: Easing.OutExpo;
duration: 300
}
}
ParallelAnimation {
YAnimator {
target: smiley;
from: smiley.maxHeight;
to: smiley.minHeight
easing.type: Easing.OutBounce;
duration: 1000
}
ScaleAnimator {
target: shadow
from: 0.5
to: 1
easing.type: Easing.OutBounce;
duration: 1000
}
}
}
PauseAnimation { duration: 500 }
running: true
loops: Animation.Infinite
}Behaviors
O “Behaviors” usa comportamentos para mover um retângulo até o local em que você clica.
// Set an 'elastic' behavior on the focusRect's y property.
Behavior on y {
NumberAnimation {
easing.type: Easing.OutElastic
easing.amplitude: 3.0
easing.period: 2.0
duration: 300
}
}Texto Oscilante
Texto oscilante demonstra o uso de comportamentos mais complexos para animar e fazer o texto oscilar enquanto você o arrasta. Isso é feito atribuindo uma ligação complexa a cada letra:
x: follow ? follow.x + follow.width : container.width / 6
y: follow ? follow.y : container.height / 2Em seguida, utiliza comportamentos para animar o movimento de cada letra:
Behavior on x { enabled: container.animated; SpringAnimation { spring: 3; damping: 0.3; mass: 1.0 } }
Behavior on y { enabled: container.animated; SpringAnimation { spring: 3; damping: 0.3; mass: 1.0 } }Tv Tennis
O “Tv Tennis” usa comportamentos complexos para fazer com que as raquetes sigam uma bola, simulando uma partida de tênis infinita. Mais uma vez, uma ligação que depende de outros valores é aplicada à posição, e um comportamento fornece a animação.
Curvas de aceleração
O “Easing Curves” mostra todas as curvas de suavização disponíveis nas animações d Qt Quick.
Estados
Estados demonstra como as propriedades de um item podem variar entre os estados.
Ele define vários estados:
// In state 'middleRight', move the image to middleRightRect
State {
name: "middleRight"
PropertyChanges {
userIcon {
x: middleRightRect.x
y: middleRightRect.y
}
}
},
// In state 'bottomLeft', move the image to bottomLeftRect
State {
name: "bottomLeft"
PropertyChanges {
userIcon {
x: bottomLeftRect.x
y: bottomLeftRect.y
}
}
}Transições
Transições utiliza o exemplo de Estados e anima as alterações nas propriedades definindo transições:
// Transitions define how the properties change when the item moves between each state
transitions: [
// When transitioning to 'middleRight' move x,y over a duration of 1 second,
// with OutBounce easing function.
Transition {
from: "*"; to: "middleRight"
NumberAnimation { properties: "x,y"; easing.type: Easing.OutBounce; duration: 1000 }
},
// When transitioning to 'bottomLeft' move x,y over a duration of 2 seconds,
// with InOutQuad easing function.
Transition {
from: "*"; to: "bottomLeft"
NumberAnimation { properties: "x,y"; easing.type: Easing.InOutQuad; duration: 2000 }
},
// For any other state changes move x,y linearly over duration of 200ms.
Transition {
NumberAnimation { properties: "x,y"; duration: 200 }
}PathAnimation
A PathAnimation anima uma imagem ao longo de uma curva Bézier usando um PathAnimation.
PathAnimation {
id: pathAnim
duration: 2000
easing.type: Easing.InQuad
target: box
orientation: PathAnimation.RightFirst
anchorPoint: Qt.point(box.width/2, box.height/2)
path: Path {
startX: 50; startY: 50
PathCubic {
x: window.width - 50
y: window.height - 50
control1X: x; control1Y: 50
control2X: 50; control2Y: y
}
onChanged: canvas.requestPaint()
}
}PathInterpolator
O PathInterpolator anima uma imagem ao longo da mesma curva Bézier, utilizando, no entanto, um PathInterpolator.
PathInterpolator {
id: motionPath
path: Path {
startX: 50; startY: 50
PathCubic {
x: window.width - 50
y: window.height - 50
control1X: x; control1Y: 50
control2X: 50; control2Y: y
}
onChanged: canvas.requestPaint()
}
SequentialAnimation on progress {
running: true
loops: -1
PauseAnimation { duration: 1000 }
NumberAnimation {
id: progressAnim
running: false
from: 0; to: 1
duration: 2000
easing.type: Easing.InQuad
}
}
}© 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.