Results 1 to 6 of 6

Thread: Qt flickering animation

  1. #1

    Default Qt flickering animation

    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)
    Qt Code:
    1. animation = new QPropertyAnimation(this, "geometry");
    2. animation->setDuration(555);
    3. animation->setEasingCurve(QEasingCurve::Linear);
    4. animation->setStartValue(QRect(availableScreenSize.width()-minWidth-WINDOW_PADDING,availableScreenSize.height()-minHeight-WINDOW_PADDING,minWidth,minHeight));
    5. animation->setEndValue(QRect(availableScreenSize.width()-maxWidth-WINDOW_PADDING,availableScreenSize.height()-maxHeight-WINDOW_PADDING,maxWidth,maxHeight));
    To copy to clipboard, switch view to plain text mode 
    2 - using a timer
    Qt Code:
    1. #include "widget.h"
    2. #include "ui_widget.h"
    3. #include <QDesktopWidget>
    4. #include <QDebug>
    5.  
    6. Widget::Widget(QWidget *parent) :
    7. QWidget(parent),
    8. ui(new Ui::Widget)
    9. {
    10. ui->setupUi(this);
    11. this->setStyleSheet("background:transparent;");
    12. this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::Tool);
    13.  
    14. availableScreenSize = qApp->desktop()->availableGeometry();
    15.  
    16. //Growing from right to left
    17. this->setGeometry(availableScreenSize.width()-165,availableScreenSize.height()-95,160,90);
    18. //Growing from left to right
    19. //this->setGeometry(200,200,160,90);
    20.  
    21. timeLine = new QTimeLine();
    22. timeLine->setDuration(2222);
    23. timeLine->setFrameRange(1, 800);
    24. connect(timeLine, SIGNAL(frameChanged(int)), this, SLOT(update()));
    25.  
    26. counter = 0;
    27.  
    28. timeLine->start();
    29. }
    30.  
    31. Widget::~Widget()
    32. {
    33. delete ui;
    34. }
    35.  
    36. void Widget::paintEvent(QPaintEvent * /* event */)
    37. {
    38. counter++;
    39. qDebug() << counter;
    40.  
    41. qApp->processEvents();
    42. //Growing from right to left
    43. this->setGeometry(availableScreenSize.width()-165-this->width()-1,availableScreenSize.height()-95-this->height()-1,this->width()+1,this->height()+1);
    44.  
    45. //Growing from left to right
    46. //this->setGeometry(200,200,this->width()+1,this->height()+1);
    47.  
    48. if(timeLine->currentFrame() == 800)
    49. {
    50. qApp->exit(1);
    51. }
    52. }
    To copy to clipboard, switch view to plain text mode 

    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!
    Last edited by high_flyer; 3rd May 2011 at 14:08. Reason: code tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt flickering animation

    Your paintEvent() is a complete junk. I'd start with fixing it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3

    Default Re: Qt flickering animation

    wysota,
    Thank you for your helpful advice!
    While thinking about your advice, i noticed that Qt is not that great with implementing the double buffering it suppose to do... i managed to overcome it by creating the animation inside a transparent larger window.
    Although it's a crappy way (unlike your much helpfull advice) it works...
    Also, i have given 2 different options - first one with qpropertyanimation , very simple and clean and still don't work.
    If you don't know the answer - please don't leave unnecessary feedback
    Thank you for your effort.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt flickering animation

    Quote Originally Posted by tomrider View Post
    While thinking about your advice, i noticed that Qt is not that great with implementing the double buffering it suppose to do...
    If you remove wheels from a car it is not much good at traveling either.

    If you don't know the answer - please don't leave unnecessary feedback
    I know your paintEvent is a junk and it is the one causing problems. If you are inside an event handler and you ask the framework to start handling events at that point (which it already is doing but you require it to loop again into the event queue and possibly reinitialize your widget which causes flickering) or you start resizing a widget when you are supposed to paint it (which causes a flicker as the widget is erased and then resized, erased again, resized, erased again and so on and is never drawn) then you are shooting yourself in the foot.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5

    Default Re: Qt flickering animation

    Any insights on the qpropertyanimation and why it's not working?
    Also, do you have any idea why double buffering is not preformed? do you have any alternatives?

    p.s - regarding your answer - how do you explain that from left to right its working smoothly and when transfering the direction to right to left it's flickering?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt flickering animation

    Quote Originally Posted by tomrider View Post
    Any insights on the qpropertyanimation and why it's not working?
    It is working. See how the title bar of your window behaves -- it also "flickers" or rather "shakes" when the window gets resized and it is not drawn by Qt but by your window manager.
    Also, do you have any idea why double buffering is not preformed? do you have any alternatives?
    It is performed. When the window size changes it is the window manager's responsibility to expose the surface for the widget. That's what causes your flickering (the swap between the old surface and the new one) and that's why it works if you use an additional larger window that doesn't get resized -- as then double buffering is done solely by Qt. You can reduce the effect you have by disabling window decorations (by setting Qt::FramelessWindowHint) or complaining to your windowing system vendor to do something about it. If it was Qt that was causing the flicker, you'd be observing it on the entire area of the widget (as the widget is erased prior to being redrawn).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. flickering in frame moving animation
    By Seth90 in forum Qt Programming
    Replies: 0
    Last Post: 23rd April 2011, 12:55
  2. Flickering problem
    By yagabey in forum Qt Programming
    Replies: 2
    Last Post: 5th May 2010, 12:25
  3. Flickering
    By Pembar in forum Qt Programming
    Replies: 2
    Last Post: 19th May 2009, 19:21
  4. QtOgreFramework flickering with qt 4.5
    By Angelo Moriconi in forum Qt Programming
    Replies: 2
    Last Post: 6th April 2009, 10:52
  5. flickering x-scale
    By sun in forum Qwt
    Replies: 2
    Last Post: 1st October 2008, 07:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.