2017-10-17 17 views

Répondre

3

La tâche est facilement résolu avec un Timer.

import QtQuick 2.6 
import QtQuick.Window 2.2 

Window { 
    visible: true 
    width: 640 
    height: 480 
    title: qsTr("Hello World") 

    Text { 
     id: my_text 
     font.pixelSize: 30 
     text: "Hello" 
    } 

    Timer{ 
     id: timer 
     interval: 1000 
     running: true 
     repeat: true 
     onTriggered: my_text.opacity = my_text.opacity === 0 ? 1 : 0 
    } 
} 
+0

Pourquoi utilisez-vous 'opacity' au lieu de' visible'? IMHO 'visible =! Visible' est plus facile à lire. Y a-t-il des avantages de performance de l'utilisation de l'opacité? – derM

0

Une autre solution à l'aide OpacityAnimator:

import QtQuick 2.6 
import QtQuick.Window 2.2 

Window { 
    visible: true 
    width: 640 
    height: 480 
    title: qsTr("Hello World") 

    Text { 
     anchors.centerIn: parent 
     id: my_text 
     text: "Hello" 
     font.pixelSize: 30 

     OpacityAnimator { 
      target: my_text; 
      from: 0; 
      to: 1; 
      duration: 400; 
      loops: Animation.Infinite; 
      running: true; 
      easing { 
       type: Easing.InOutExpo; 
      } 
     } 
    } 
}