3
votes

I'm developing a simple test app with Qt for Android. I'm trying to animate every user touch on the screen by showing semi-transparent circle, that increases its radius from 0 to 100 for example.

I added a custom QLabel on top of all widgets. And I'm trying to animate its QPixmap by updating it with QPropertyAnimation for custom property

Q_PROPERTY(QRect circleGeometry READ getCircleGeometry WRITE setCircleGeometry)

The setter is:

void CircleLabel::setCircleGeometry(QRect circleGeometry)
{
    QPixmap pixmap(this->size());
    pixmap.fill(Qt::transparent);

    QPainter painter(&pixmap);
    painter.setOpacity(0.2);
    painter.setPen(QPen(Qt::transparent));
    painter.setBrush(QBrush(Qt::white));
    painter.setRenderHint(QPainter::Antialiasing);

    painter.drawEllipse(circleGeometry);

    this->setPixmap(pixmap);
}

I see, that the setter is too heavy for the animation, so it runs slow on my android device. Could you please advice me how can I modify my animation to make it fast and smooth.

1

1 Answers

0
votes

So... My solution in to create a vector of QPixmaps once, on application start, and then my CircleLabel::setCircleGeometry will look like:

void CircleLabel::setCircleGeometry(int currentIdx)
{
    this->setPixmap(preGeneratedPixmaps[currentIdx]);
}