Answer the question
In order to leave comments, you need to log in
How to get rid of flickering animation in Qt?
We need to make an animation: make the widget move smoothly from one position to another in a straight line.
I am using QPropertyAnimation. With its help I move my widget.
Animation creation code
Node* a = new Node(this);
a->show();
QPropertyAnimation* anim = new QPropertyAnimation(a, "geometry", this);
anim->setStartValue(QRect(0, 0, m_rectSize, m_rectSize));
anim->setEndValue (QRect(0, 250, m_rectSize, m_rectSize));
anim->setDuration(500);
anim->start(QPropertyAnimation::DeleteWhenStopped);
void Node::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
int size = height();
QRect currentRect(0, 0, size, size);
painter.setPen (m_color);
painter.setBrush(m_color);
painter.drawRoundedRect(currentRect, size/5, size/5);
}
Answer the question
In order to leave comments, you need to log in
Do double buffering. Your widget will be redrawn each time it is moved. You can check this: add a call to the qDebug()<<__FUNCTION__ function in onPaint and look in the debugger.
www.informit.com/articles/article.aspx?p=1405227&s...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question