Hi.

I have a small testproject, where I have painted a roundedrect box, that I want to animate. My problem is that I can't get the animation to run smoothly.

The painted box is animated with a duration of 1000ms, and "stutters" frequently while moving across the dialog.

This is the code for the roundedrect box:

Qt Code:
  1. #include "groupbox.h"
  2. #include <QPainter>
  3. #include <QDebug>
  4.  
  5. GroupBox::GroupBox(QWidget *parent)
  6. : QWidget(parent)
  7. {
  8. }
  9.  
  10. GroupBox::~GroupBox()
  11. {
  12. }
  13.  
  14. void GroupBox::paintEvent(QPaintEvent *)
  15. {
  16. QPainter painter;
  17. painter.begin(this);
  18. painter.setRenderHint(QPainter::Antialiasing);
  19. painter.setPen(QPen(QBrush(qRgb(128,128,128)), 5));
  20. painter.setBrush(QBrush(qRgb(46,46,46)));
  21. painter.drawRoundedRect(QRect(35,35,250,150),25,25);
  22.  
  23. painter.end();
  24.  
  25. }
To copy to clipboard, switch view to plain text mode 

And here is the code for the animation part:
Qt Code:
  1. #include "dialog.h"
  2. #include <QDebug>
  3.  
  4. Dialog::Dialog(QWidget *parent)
  5. : QDialog(parent)
  6. {
  7. resize(1400,600);
  8.  
  9. m_group = new GroupBox(this);
  10. m_group->resize(310,200);
  11. m_group->show();
  12.  
  13. m_animation = new QPropertyAnimation(m_group, "pos", this);
  14. m_animation->setDuration(1000);
  15. m_animation->setEasingCurve(QEasingCurve::Linear);
  16.  
  17. // Continuous animation from startup
  18. m_group->move(10, 0);
  19.  
  20.  
  21. animateMove();
  22. connect(m_animation, SIGNAL(finished()), this, SLOT(animateMove()));
  23. }
  24.  
  25. Dialog::~Dialog()
  26. {
  27. }
  28.  
  29.  
  30. void Dialog::animateMove()
  31. {
  32. if (m_group->pos().x() != 10)
  33. {
  34. m_animation->setStartValue(m_group->pos());
  35. m_animation->setEndValue(QPointF(10.0,0.0));
  36. m_animation->start();
  37. }
  38. else
  39. {
  40. m_animation->setStartValue(m_group->pos());
  41. m_animation->setEndValue(QPointF(1000.0,10.0));
  42. m_animation->start();
  43. }
  44.  
  45. }
To copy to clipboard, switch view to plain text mode 

This has been tested on Linux and Windows with debug and release having the same result.

Thanks in advance for any help/hints!