PDA

View Full Version : [SOLVED] QPropertyAnimation "text" property in QLabel



AlekseyK
7th December 2010, 16:27
QLabel animation does not work - need to implement text blinking (flashing) after some time periods. What I'm doing wrong?

Code is following:

m_p1stHeaderAnimation = new QPropertyAnimation(ui.m_labelHeader1, "text", this);
m_p3rdHeaderAnimation = new QPropertyAnimation(ui.m_labelHeader3, "text", this);
...
m_p1stHeaderAnimation->setDuration(1300);
m_p1stHeaderAnimation->setKeyValueAt(0, "Flashing text 1");
m_p1stHeaderAnimation->setKeyValueAt(0.77, "");
m_p1stHeaderAnimation->setKeyValueAt(1, "");
m_p1stHeaderAnimation->setLoopCount(5);

/// Setups 3rd header animation
m_p3rdHeaderAnimation->setDuration(1300);
m_p3rdHeaderAnimation->setKeyValueAt(0, "Flashing text 3");
m_p3rdHeaderAnimation->setKeyValueAt(0.77, "");
m_p3rdHeaderAnimation->setKeyValueAt(1, "");
m_p3rdHeaderAnimation->setLoopCount(5);
...
// Start next header animation after previous
connect(m_p1stHeaderAnimation, SIGNAL(finished()), m_p3rdHeaderAnimation, SLOT(start()));
connect(m_p3rdHeaderAnimation, SIGNAL(finished()), m_p1stHeaderAnimation, SLOT(start()));
...
m_p1stHeaderAnimation->start();
m_labelHeader1 and m_labelHeader3 - QLabel class objects.

I even tied signals valueChanged to repaint slots just to be safe:

disconnect(m_p1stHeaderAnimation, SIGNAL(valueChanged(QVariant)), ui.m_labelHeader1, SLOT(repaint()));
disconnect(m_p3rdHeaderAnimation, SIGNAL(valueChanged(QVariant)), ui.m_labelHeader3, SLOT(repaint()));
but it does not work anyway. Why?

wysota
7th December 2010, 16:37
QPropertyAnimation doesn't know how to animate text.

AlekseyK
7th December 2010, 17:32
I see:


Not all QVariant types are supported. Below is a list of currently supported QVariant types:
Int
Double
Float
QLine
QLineF
QPoint
QPointF
QSize
QSizeF
QRect
QRectF
QColor


If you need to interpolate other variant types, including custom types, you have to implement interpolation for these yourself.

Added after 43 minutes:

Probably QStateMachine could help here but I do not understand how currently?

AlekseyK
7th December 2010, 18:46
I implemented correctly, only need to add Interpolator for QString like this for example:


qRegisterAnimationInterpolator<QString>(StringInterpolator);

QVariant StringInterpolator(const QString &start, const QString &end, qreal progress)
{
if(progress < 1.0)
return start;
else
return end;
}

Animations for any other types are possible with such approach.