Jumping/stuttering during animation QPainter
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:
Code:
#include "groupbox.h"
#include <QPainter>
#include <QDebug>
GroupBox
::GroupBox(QWidget *parent
){
}
GroupBox::~GroupBox()
{
}
{
painter.begin(this);
painter.
setRenderHint(QPainter::Antialiasing);
painter.
setPen(QPen(QBrush(qRgb
(128,
128,
128)),
5));
painter.
setBrush(QBrush(qRgb
(46,
46,
46)));
painter.
drawRoundedRect(QRect(35,
35,
250,
150),
25,
25);
painter.end();
}
And here is the code for the animation part:
Code:
#include "dialog.h"
#include <QDebug>
{
resize(1400,600);
m_group = new GroupBox(this);
m_group->resize(310,200);
m_group->show();
m_animation = new QPropertyAnimation(m_group, "pos", this);
m_animation->setDuration(1000);
m_animation->setEasingCurve(QEasingCurve::Linear);
// Continuous animation from startup
m_group->move(10, 0);
animateMove();
connect(m_animation, SIGNAL(finished()), this, SLOT(animateMove()));
}
Dialog::~Dialog()
{
}
void Dialog::animateMove()
{
if (m_group->pos().x() != 10)
{
m_animation->setStartValue(m_group->pos());
m_animation
->setEndValue
(QPointF(10.0,
0.0));
m_animation->start();
}
else
{
m_animation->setStartValue(m_group->pos());
m_animation
->setEndValue
(QPointF(1000.0,
10.0));
m_animation->start();
}
}
This has been tested on Linux and Windows with debug and release having the same result.
Thanks in advance for any help/hints!