Advertisement
adaitabehera

CrossFadeTextAnimation

Jul 28th, 2020 (edited)
3,162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 1.95 KB | None | 0 0
  1. import QtQuick 2.12
  2. import QtQuick.Window 2.12
  3. Window {
  4.     visible: true
  5.     width: 640
  6.     height: 480
  7.     title: qsTr("Hello World")
  8.     Rectangle {
  9.         id: root
  10.         anchors.fill: parent
  11.         color: "#181C21"
  12.         property var texts: ["First Text", "Second Text", "Third Text", "Fourth Text", "Fifth Text"]
  13.         property int index: 0
  14.         Text {
  15.             id: text1
  16.             anchors.fill: parent
  17.             verticalAlignment: Text.AlignVCenter
  18.             horizontalAlignment: Text.AlignHCenter
  19.             font.pixelSize: 30
  20.             color: "white"
  21.             text: root.texts[0]
  22.         }
  23.         Text {
  24.             id: text2
  25.             anchors.fill: parent
  26.             verticalAlignment: Text.AlignVCenter
  27.             horizontalAlignment: Text.AlignHCenter
  28.             font.pixelSize: 30
  29.             color: "white"
  30.             text: root.texts[1]
  31.             opacity: 0.0
  32.         }
  33.         ParallelAnimation {
  34.             id: text1ToText2
  35.             running: false
  36.             PropertyAnimation { target: text1; property: "opacity"; to: 0.0; duration: 1000;}
  37.             PropertyAnimation { target: text2; property: "opacity"; to: 1.0; duration: 1000 }
  38.         }
  39.         ParallelAnimation {
  40.             id: text2ToText1
  41.             running: false
  42.             PropertyAnimation { target: text2; property: "opacity"; to: 0.0; duration: 1000;}
  43.             PropertyAnimation { target: text1; property: "opacity"; to: 1.0; duration: 1000 }
  44.         }
  45.         MouseArea {
  46.             anchors.fill: parent
  47.             onClicked: {
  48.                 root.index = (root.index + 1) % root.texts.length
  49.                 if(text1.opacity == 0.0) {
  50.                     text1.text = root.texts[root.index]
  51.                     text2ToText1.start()
  52.                 } else {
  53.                     text2.text = root.texts[root.index]
  54.                     text1ToText2.start()
  55.                 }
  56.             }
  57.         }
  58.     }
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement