Results 1 to 5 of 5

Thread: Background color animation

  1. #1
    Join Date
    Oct 2011
    Posts
    51
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Background color animation

    Hi!

    I want to animate changing of background color in a window using QPropertyAnimation
    Qt Code:
    1. QPalette start;
    2. start.setColor(QPalette::Window, QColor(1,255,0));
    3.  
    4. QPalette stop;
    5. stop.setColor(QPalette::Window, QColor(255,255,255));
    6. animation = new QPropertyAnimation(this, "palette");
    7. animation->setDuration(100);
    8. animation->setStartValue(start);
    9. animation->setEndValue(stop);
    10. animation->setLoopCount(-1);
    11. animation->start();
    To copy to clipboard, switch view to plain text mode 

    But after "starting" the animation nothing happen...
    Is there a way to change the background color of window by simple calling some property? (Without overloading or creating own properties by Q_PROPERTY)

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Background color animation

    Did you call setAutoFillBackground(true) on the widget?

    Cheers,
    _

  3. #3
    Join Date
    Oct 2011
    Posts
    51
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Background color animation

    Yes, I add that line, without any good result

    Qt Code:
    1. ui->setupUi(this);
    2. this->setAutoFillBackground(true);
    3. QPalette start, stop;
    4.  
    5. start.setColor(QPalette::Window, QColor(0,255,0));
    6. stop.setColor(QPalette::Window, QColor(255,0,0));
    7. animation = new QPropertyAnimation(this, "palette");
    8. animation->setDuration(100);
    9. animation->setStartValue(start);
    10. animation->setEndValue(stop);
    11. animation->setLoopCount(-1);
    12.  
    13. connect(ui->pushButton, &QPushButton::clicked,
    14. [&](){
    15. qDebug() << "Animation button clicked";
    16. animation->start();
    17. });
    To copy to clipboard, switch view to plain text mode 

    This is the whole "app" that I was testing animations on... (standard new mainwindow project from qtcreator with pushbutton)
    some further suggestions?

  4. #4
    Join Date
    Oct 2011
    Posts
    51
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Background color animation

    One thing that worked was to add own "color" property to widget.

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Background color animation

    The problem could be that QPropertyAnimation does not know how to interpolate between QPalette values since a QPalette is quite a complex object with lots of sub values.

    Cheers,
    _

Similar Threads

  1. Get background color of QPushbutton
    By MickyJhon in forum Qt Programming
    Replies: 6
    Last Post: 7th February 2014, 16:45
  2. Background color
    By FelixB in forum Qwt
    Replies: 4
    Last Post: 24th June 2013, 07:03
  3. QGraphicsObject color change animation
    By mvbhavsar in forum Newbie
    Replies: 8
    Last Post: 30th August 2011, 13:34
  4. background color for QGraphicsWidget
    By QAir in forum Qt Programming
    Replies: 1
    Last Post: 16th July 2009, 14:52
  5. QTextTable background color?
    By anupamgee in forum Qt Programming
    Replies: 0
    Last Post: 26th June 2009, 10:40

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.