Results 1 to 7 of 7

Thread: Painting / moving in a single step to avoid flickering

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2007
    Posts
    53
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question Painting / moving in a single step to avoid flickering

    As it was not related to an ARGB widget and there is no answer, I start a new short thread to know if there is a solution to this problem.

    I will take the shaped clock sample to explain. I've attached the modified code to this message.

    Here is what I've had in the shapedclock.h :

    Qt Code:
    1. protected:
    2. void timerEvent(QTimerEvent *event); // <==
    3. void mouseMoveEvent(QMouseEvent *event);
    4.  
    5. private:
    6. QPoint dragPosition;
    7. int step; // <==
    8. QBasicTimer timer; // <==
    To copy to clipboard, switch view to plain text mode 

    Here is what I've had in the shapedclock's constructor

    Qt Code:
    1. setWindowTitle(tr("Shaped Analog Clock"));
    2.  
    3. step = 0; // <==
    4. this->timer.start(200, this); // <==
    To copy to clipboard, switch view to plain text mode 

    Here is the added timerEvent() method :

    Qt Code:
    1. void ShapedClock::timerEvent(QTimerEvent *event)
    2. {
    3. if(event->timerId() == timer.timerId())
    4. {
    5. ++step;
    6. resize(width() + step, height() + step);
    7. update();
    8. }
    9. else
    10. QWidget::timerEvent(event);
    11. }
    To copy to clipboard, switch view to plain text mode 

    And finally, here is the added line in resizeEvent for moving the widget on screen :

    Qt Code:
    1. void ShapedClock::resizeEvent(QResizeEvent * /* event */)
    2. {
    3. move(x() - 5, y() - 5);
    To copy to clipboard, switch view to plain text mode 

    And you will see clearly the clock shaking when resizing / moving.

    As I told in my previous post, there is a simple way to deal with it. Defining a larger size QWidget and painting at the correct location. But for a very large widget that can grow by more than 3 times its size and can be shifted by more than 2 times its size, it consume much more memory and perhaps it won't be efficient to deal with a large QWidget even if it contains reserved transparency areas for growing / offseting ?

    So, do you think there is a way to paint and move in a single step to avoid dealing with a very large QWidget just to solve this shaking motion ?

    Thanks for your answer on this very tricky problem.
    Attached Files Attached Files

Similar Threads

  1. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.