C
C
cerevra2014-09-28 21:58:52
Qt
cerevra, 2014-09-28 21:58:52

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);

And rendering inside Node. (her part)
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);
}

Animation works. But! Flickers. Moreover, flickering occurs only in those parts of the Node where there are fillets. If the rounding is turned off, everything is beautiful and without lags. But you can't turn them off.
Any ideas how to fix this?
Thanks
UPD: you can add something else that at a high animation speed (100-200 µs), i.e. with the rapid movement of the square, it flickers all over.
UPD2: Windows 7 x64

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Danilevsky, 2014-10-02
@cerevra

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...

A
Andrey Burov, 2014-09-29
@BuriK666

This looks like a Qt bug, try a different version.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question