Results 1 to 4 of 4

Thread: [SOLVED] QPropertyAnimation "text" property in QLabel

  1. #1
    Join Date
    Nov 2010
    Posts
    47
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default [SOLVED] QPropertyAnimation "text" property in QLabel

    QLabel animation does not work - need to implement text blinking (flashing) after some time periods. What I'm doing wrong?

    Code is following:
    Qt Code:
    1. m_p1stHeaderAnimation = new QPropertyAnimation(ui.m_labelHeader1, "text", this);
    2. m_p3rdHeaderAnimation = new QPropertyAnimation(ui.m_labelHeader3, "text", this);
    3. ...
    4. m_p1stHeaderAnimation->setDuration(1300);
    5. m_p1stHeaderAnimation->setKeyValueAt(0, "Flashing text 1");
    6. m_p1stHeaderAnimation->setKeyValueAt(0.77, "");
    7. m_p1stHeaderAnimation->setKeyValueAt(1, "");
    8. m_p1stHeaderAnimation->setLoopCount(5);
    9.  
    10. /// Setups 3rd header animation
    11. m_p3rdHeaderAnimation->setDuration(1300);
    12. m_p3rdHeaderAnimation->setKeyValueAt(0, "Flashing text 3");
    13. m_p3rdHeaderAnimation->setKeyValueAt(0.77, "");
    14. m_p3rdHeaderAnimation->setKeyValueAt(1, "");
    15. m_p3rdHeaderAnimation->setLoopCount(5);
    16. ...
    17. // Start next header animation after previous
    18. connect(m_p1stHeaderAnimation, SIGNAL(finished()), m_p3rdHeaderAnimation, SLOT(start()));
    19. connect(m_p3rdHeaderAnimation, SIGNAL(finished()), m_p1stHeaderAnimation, SLOT(start()));
    20. ...
    21. m_p1stHeaderAnimation->start();
    To copy to clipboard, switch view to plain text mode 
    m_labelHeader1 and m_labelHeader3 - QLabel class objects.

    I even tied signals valueChanged to repaint slots just to be safe:
    Qt Code:
    1. disconnect(m_p1stHeaderAnimation, SIGNAL(valueChanged(QVariant)), ui.m_labelHeader1, SLOT(repaint()));
    2. disconnect(m_p3rdHeaderAnimation, SIGNAL(valueChanged(QVariant)), ui.m_labelHeader3, SLOT(repaint()));
    To copy to clipboard, switch view to plain text mode 
    but it does not work anyway. Why?
    Last edited by AlekseyK; 7th December 2010 at 18:58. Reason: updated contents

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPropertyAnimation "text" property in QLabel

    QPropertyAnimation doesn't know how to animate text.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2010
    Posts
    47
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPropertyAnimation "text" property in QLabel

    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?
    Last edited by AlekseyK; 7th December 2010 at 17:32.

  4. #4
    Join Date
    Nov 2010
    Posts
    47
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPropertyAnimation "text" property in QLabel

    I implemented correctly, only need to add Interpolator for QString like this for example:

    Qt Code:
    1. qRegisterAnimationInterpolator<QString>(StringInterpolator);
    2.  
    3. QVariant StringInterpolator(const QString &start, const QString &end, qreal progress)
    4. {
    5. if(progress < 1.0)
    6. return start;
    7. else
    8. return end;
    9. }
    To copy to clipboard, switch view to plain text mode 

    Animations for any other types are possible with such approach.

Similar Threads

  1. Replies: 3
    Last Post: 8th December 2011, 19:21
  2. Replies: 1
    Last Post: 7th April 2010, 21:46
  3. Replies: 4
    Last Post: 5th March 2010, 18:03
  4. Replies: 3
    Last Post: 15th February 2010, 17:27
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.