tomrider
1st May 2011, 07:34
Hi Everyone,
I have a problem creating a simple animation with Qt animation.
I have a small image located at the bottom right corner of the screen, i am trying to create animation that will enlarge the picture by streching it from the the top left corner of the image and streching it to the center of the screen.
I managed to do that, but, it's very notiable that qanimation makes it flicker (the right border of the picture, and it doesn't turns out good)
I also did that with no animation, but with a timer, and changing window geometry , but i had the same problem, seems that it's not refreshing fast enough, creating flickering in the right border of the picture.
here are the 2 examples:
1 - using property animation (geometery)
animation = new QPropertyAnimation(this, "geometry");
animation->setDuration(555);
animation->setEasingCurve(QEasingCurve::Linear);
animation->setStartValue(QRect(availableScreenSize.width()-minWidth-WINDOW_PADDING,availableScreenSize.height()-minHeight-WINDOW_PADDING,minWidth,minHeight));
animation->setEndValue(QRect(availableScreenSize.width()-maxWidth-WINDOW_PADDING,availableScreenSize.height()-maxHeight-WINDOW_PADDING,maxWidth,maxHeight));
2 - using a timer
#include "widget.h"
#include "ui_widget.h"
#include <QDesktopWidget>
#include <QDebug>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
this->setStyleSheet("background:transparent;");
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::Tool);
availableScreenSize = qApp->desktop()->availableGeometry();
//Growing from right to left
this->setGeometry(availableScreenSize.width()-165,availableScreenSize.height()-95,160,90);
//Growing from left to right
//this->setGeometry(200,200,160,90);
timeLine = new QTimeLine();
timeLine->setDuration(2222);
timeLine->setFrameRange(1, 800);
connect(timeLine, SIGNAL(frameChanged(int)), this, SLOT(update()));
counter = 0;
timeLine->start();
}
Widget::~Widget()
{
delete ui;
}
void Widget::paintEvent(QPaintEvent * /* event */)
{
counter++;
qDebug() << counter;
qApp->processEvents();
//Growing from right to left
this->setGeometry(availableScreenSize.width()-165-this->width()-1,availableScreenSize.height()-95-this->height()-1,this->width()+1,this->height()+1);
//Growing from left to right
//this->setGeometry(200,200,this->width()+1,this->height()+1);
if(timeLine->currentFrame() == 800)
{
qApp->exit(1);
}
}
Now the weired thing here is that if the animation is from left 2 right - it looks smooth... once the direction is changed from right 2 left the entire right border is "jumpy" .
I'll appriciate any help that you can give me.
Thanks!
I have a problem creating a simple animation with Qt animation.
I have a small image located at the bottom right corner of the screen, i am trying to create animation that will enlarge the picture by streching it from the the top left corner of the image and streching it to the center of the screen.
I managed to do that, but, it's very notiable that qanimation makes it flicker (the right border of the picture, and it doesn't turns out good)
I also did that with no animation, but with a timer, and changing window geometry , but i had the same problem, seems that it's not refreshing fast enough, creating flickering in the right border of the picture.
here are the 2 examples:
1 - using property animation (geometery)
animation = new QPropertyAnimation(this, "geometry");
animation->setDuration(555);
animation->setEasingCurve(QEasingCurve::Linear);
animation->setStartValue(QRect(availableScreenSize.width()-minWidth-WINDOW_PADDING,availableScreenSize.height()-minHeight-WINDOW_PADDING,minWidth,minHeight));
animation->setEndValue(QRect(availableScreenSize.width()-maxWidth-WINDOW_PADDING,availableScreenSize.height()-maxHeight-WINDOW_PADDING,maxWidth,maxHeight));
2 - using a timer
#include "widget.h"
#include "ui_widget.h"
#include <QDesktopWidget>
#include <QDebug>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
this->setStyleSheet("background:transparent;");
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::Tool);
availableScreenSize = qApp->desktop()->availableGeometry();
//Growing from right to left
this->setGeometry(availableScreenSize.width()-165,availableScreenSize.height()-95,160,90);
//Growing from left to right
//this->setGeometry(200,200,160,90);
timeLine = new QTimeLine();
timeLine->setDuration(2222);
timeLine->setFrameRange(1, 800);
connect(timeLine, SIGNAL(frameChanged(int)), this, SLOT(update()));
counter = 0;
timeLine->start();
}
Widget::~Widget()
{
delete ui;
}
void Widget::paintEvent(QPaintEvent * /* event */)
{
counter++;
qDebug() << counter;
qApp->processEvents();
//Growing from right to left
this->setGeometry(availableScreenSize.width()-165-this->width()-1,availableScreenSize.height()-95-this->height()-1,this->width()+1,this->height()+1);
//Growing from left to right
//this->setGeometry(200,200,this->width()+1,this->height()+1);
if(timeLine->currentFrame() == 800)
{
qApp->exit(1);
}
}
Now the weired thing here is that if the animation is from left 2 right - it looks smooth... once the direction is changed from right 2 left the entire right border is "jumpy" .
I'll appriciate any help that you can give me.
Thanks!