Results 1 to 2 of 2

Thread: QPropertyAnimation does not redraw the object

  1. #1
    Join Date
    Jun 2014
    Posts
    1
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QPropertyAnimation does not redraw the object

    These are my very first steps in Qt. I am trying to create a simple animation (under Ubuntu, Qt 4.8), and I don't think I am setting things up correctly.

    I have a class MyWidget, inherited from QWidget:

    Qt Code:
    1. class MyWidget : public QWidget
    2. {
    3. Q_OBJECT
    4. Q_PROPERTY(double rmin READ rmin WRITE setmin)
    5.  
    6. public:
    7. MyWidget();
    8. double rmin() const;
    9. void setmin(double m);
    10. ...
    11.  
    12. protected:
    13. void paintEvent(QPaintEvent *event);
    14. signals:
    15.  
    16. public slots:
    17. private:
    18. double p_rmin;
    19. ...
    20. };
    To copy to clipboard, switch view to plain text mode 

    The getter and setter functions for the property are
    Qt Code:
    1. double MyWidget::rmin() const{
    2. return p_rmin;
    3. }
    4.  
    5. void MyWidget::setmin(double m){
    6. p_rmin=m;
    7. }
    To copy to clipboard, switch view to plain text mode 

    The function
    Qt Code:
    1. void MyWidget::paintEvent(QPaintEvent *event)
    To copy to clipboard, switch view to plain text mode 
    uses the variable p_rmin to draw something (it access the variable only through the getter). Finally, my main() is:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. MyWidget w;
    5. w.show();
    6.  
    7. QPropertyAnimation* animation = new QPropertyAnimation(&w, "rmin");
    8. animation->setDuration(5000);
    9.  
    10. animation->setStartValue(2.5);
    11. animation->setEndValue(3.3);
    12.  
    13. animation->start(QAbstractAnimation::DeleteWhenStopped);
    14. return a.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 

    When I run this, I only see the static picture that was drawn for the starting value of p_rmin (which was also initialised by the constructor of MyWidget). But every time I resize the window, or switch between windows, and thereby force a redraw, I see a picture for a corresponding intermediate value. If I include a call to update() in the property setter, then the animation works. Surely, the animate object should be forcing a redraw if I had set up things correctly? Many thanks in advance!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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 does not redraw the object

    No, the animation only makes a property change. It is up to the property setter to inform the widget that the new value of the property requires the widget to be updated. Therefore your initial approach of adding an update() call to setmin() was correct.
    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. The following user says thank you to wysota for this useful post:

    Idefix82 (12th June 2014)

Similar Threads

  1. TypeError: Object [object Object] has no method 'sendData'
    By TheIndependentAquarius in forum Qt Quick
    Replies: 2
    Last Post: 30th November 2013, 06:54
  2. Don't redraw desktop, use a screenshot instead.
    By danciac in forum Qt Programming
    Replies: 2
    Last Post: 8th September 2010, 12:40
  3. How can I redraw the QTreeWidgetITem?
    By cspp in forum Qt Programming
    Replies: 13
    Last Post: 14th May 2009, 12:50
  4. how to redraw cube to rectangle
    By wagmare in forum Qt Programming
    Replies: 6
    Last Post: 11th February 2009, 06:26
  5. QSystemTrayIcon Redraw Problems
    By December in forum Qt Programming
    Replies: 0
    Last Post: 7th December 2008, 07:12

Tags for this Thread

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.