PDA

View Full Version : Animation in Qt



trasher
19th May 2014, 22:46
Hey

I have a problem with animation in Qt. The problem is that the position of animated objects is always the same, except the time when the window loses focus and regains it. When the window is resized those object have tendency to 'disappear'. I mean the frame is okay, but its content is not.

Picture of frame before resize
10372

...and after
10371



QGridLayout *gridLayout = new QGridLayout();
QFrame *frame = new QFrame();
frame->setLineWidth(3);
frame->setMidLineWidth(3);
frame->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);

QVBoxLayout *layout = new QVBoxLayout(frame);

QLabel *label = new QLabel("label", frame);
label->setEnabled(false);

QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(label);
effect->setOpacity(1.0);
label->setGraphicsEffect(effect);

layout->addWidget(label, 0, Qt::AlignHCenter);
gridLayout->addWidget(frame, 0, 0, 1, 1, Qt::AlignHCenter | Qt::AlignVCenter);

QPropertyAnimation *animation = new QPropertyAnimation(effect, "opacity");
animation->setDuration(500);
animation->setStartValue(0.0);
animation->setEndValue(effect->opacity());
animation->setEasingCurve(QEasingCurve::OutQuad);
animation->start(QAbstractAnimation::DeleteWhenStopped);