PDA

View Full Version : Resize QWidget using QPropertyAnimation



das.joyita
9th December 2016, 16:03
How do you create an animation where an item scales up in size, then scales down to its original size (think of a "bouncing ball" from a top/bird's eye view). So far I have only figured out how to create a one-way animation using using x and y coordinates with positioning the widget to move from one part of the screen to other.

12243

My requirement is to make the central grid in the attached picture to expand and then minimize to its position (like a bouncing ball from top view). I am using the following code but there is no change in the size. Please let me know what is the right approach.



int duration2 = 1000;
QPropertyAnimation *animation = new QPropertyAnimation(ui->frame, "size"); //maximumSize");// "geometry");
animation->setDuration(duration2);
animation->setStartValue(QSize(400, 400)); //QRect(735,415,300,300));
animation->setEndValue(QSize(1600, 1600));
//animation->setEasingCurve(QEasingCurve::OutBounce);

QPropertyAnimation *animation2 = new QPropertyAnimation(ui->graphicsView, "size");
animation2->setDuration(duration2);
animation2->setStartValue(QSize(400, 400)); //QRect(735,415,300,300));
animation2->setEndValue(QSize(1600, 1600));//QRect(735,115,300,300));
// animation2->setEasingCurve(QEasingCurve::OutBounce);

QParallelAnimationGroup *group2 = new QParallelAnimationGroup;
group2->addAnimation(animation);
group2->addAnimation(animation2);
group2->start();


Added after 12 minutes:

I found out the problem, each frame here contains a grid layout and each grid contains labels holding an image of the blobs in pixmap. Now when I increase the size of the labels , it pushes the image out and the images dont expand. How do I get the images in each of the label to expand.

anda_skoa
9th December 2016, 16:15
If you want QLabels to scale their content see QLabel::setScaledContents().

Cheers,
_

das.joyita
9th December 2016, 17:32
yes it works now. Thanks.