LearnUntillDeath
LearnUntillDeath

Reputation: 35

How to make the QT text to reappear(Blink) every few milli seconds

I have a text element in my window and I would like it be blink or appear and disappear for every few seconds or milli seconds.

My code is:

import QtQuick 2.6
import QtQuick.Window 2.2

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

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

Upvotes: 3

Views: 1553

Answers (2)

Marek R
Marek R

Reputation: 38082

Another solution using 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;
            }
        }
    }
}

Upvotes: 1

eyllanesc
eyllanesc

Reputation: 244162

The task is easily solved with a 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
     }
}

Upvotes: 5

Related Questions