2

QPropertyAnimation produces periodic flicker/drag effect during animation of longer duration of about 1 second or two. For small duration animation (about 500 ms or less) the QPropertyAnimation produces smooth animation without that specific flicker/drag effect. That flicker/drag like effect appears round about every 500ms. And i need to come across some solution as soon as possible. I have attached the minimal compilable example reproducing the problem. Please have a look and help.

I am using Qt5.5 in Windows10, i use both MinGW and Visual Studio 2013 compilers, Core i5 Laptop.

#include <QCoreApplication>
#include <QWidget>
#include <QVBoxLayout>
#include <QPushButton>
#include <QLabel>
#include <QPropertyAnimation>
#include <QApplication>


class Widget : public QWidget {
  Q_OBJECT
public:
  Widget(QWidget *parent = 0) : QWidget(parent) {
    QVBoxLayout *l = new QVBoxLayout(this);
    placeholder = new QWidget;
    placeholder->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    l->addWidget(placeholder);
    QPushButton *b = new QPushButton;
    l->addWidget(b);
    b->setText("click");
    connect(b, SIGNAL(clicked()), this, SLOT(nextPage()));
    current = 0;
  }
public slots:
  void nextPage() {
    QWidget *newPage = new QLabel("page");
    newPage->setAutoFillBackground(true);
    QStringList c = QColor::colorNames();
    QPalette p = newPage->palette();
    p.setColor(QPalette::Window, QColor(c.at(qrand() % c.size())));
    newPage->setPalette(p);
    newPage->setParent(placeholder);
    QPropertyAnimation *anim = new QPropertyAnimation(newPage, "geometry", newPage);
    QRect start = placeholder->rect();
    start.setTopLeft(start.topRight());
    newPage->setGeometry(start);
    anim->setStartValue(start);
    anim->setEndValue(placeholder->rect());
    anim->setDuration(4000);
    anim->start();

    if(current) {
      QPropertyAnimation *anim = new QPropertyAnimation(current, "geometry", current);
      anim->setStartValue(placeholder->rect());
      QRect r = placeholder->rect();
      r.translate(-r.width(), 0);
      anim->setEndValue(r);
      anim->setDuration(4000);
      connect(anim, SIGNAL(finished()), current, SLOT(deleteLater()));
      anim->start();
    }

    current = newPage;
    current->show();
  }
private:
  QWidget *placeholder;
  QWidget *current;
};

#include "main.moc"

int main(int argc, char **argv) {
  QApplication app(argc, argv);
  Widget w;
  w.show();
  return app.exec();
}
Shuji
  • 624
  • 1
  • 8
  • 24
  • Not sure, but try to use `setAutoFillBackground( false );` – Dmitry Sazonov Jan 12 '16 at 09:03
  • @SaZ this has no effect – Shuji Jan 12 '16 at 09:07
  • @SaZ Can you please point me to some way around to have smooth transition effect either by using QPropertyAnimation or any other way? I also need such a transition effect for QGraphicsView centerOn feature somewhere else. – Shuji Jan 12 '16 at 09:14
  • Other way: use QtQuick instead of widgets. Animations with widgets - it's a "bicycle" feature. Another idea - flickering is because you are animating something with layouts. – Dmitry Sazonov Jan 12 '16 at 09:50
  • 1
    Possible workaround: take a snapshot of a widget content and animate it as a pixmap movement / resizing. Animation of images will be 100% smooth, but with some artifacts. – Dmitry Sazonov Jan 12 '16 at 09:54
  • My utmost attempt is to get it working with widgets instead of QtQuick as i have done a lot of coding and don't want to spend more time. I am unfortunate enough that i got this transition in my way. – Shuji Jan 12 '16 at 09:57
  • Your idea of snapshot is good but i have elements that update randomly as the data comes in. – Shuji Jan 12 '16 at 09:58
  • @SaZ have you tried my code on your system and does the same problem appear on your system too? – Shuji Jan 12 '16 at 10:03
  • You don't need to update anything during animation. Because users really can't track any changes during animation process. Sorry, I didn't tried, I currently have no Qt installed on my laptop. – Dmitry Sazonov Jan 12 '16 at 10:42

0 Answers0