Results 1 to 12 of 12

Thread: How can I avoid the paintEvent after resizing a widget?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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: How can I avoid the paintEvent after resizing a widget?

    Ok, but how does it differ in your case? Qt calls update() upon resize as well...
    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.


  2. #2
    Join Date
    Sep 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can I avoid the paintEvent after resizing a widget?

    Quote Originally Posted by wysota View Post
    Ok, but how does it differ in your case? Qt calls update() upon resize as well...
    yes, It differ in my case at least when I create my widget as a top level widget. look at the following code(from qapplication_win.cpp) :
    Qt Code:
    1. QResizeEvent e(newSize, oldSize);
    2. QApplication::sendSpontaneousEvent(this, &e);
    3. if (d_func()->paintOnScreen()) {
    4. QRegion updateRegion(rect());
    5. if (testAttribute(Qt::WA_StaticContents))
    6. updateRegion -= QRect(0, 0, oldSize.width(), oldSize.height());
    7. d_func()->syncBackingStore(updateRegion);
    8. } else {
    9. d_func()->syncBackingStore();
    10. }
    To copy to clipboard, switch view to plain text mode 

    Qt will just send resizeEvent to my widget and I don't see any of the event handler will call update(). In fact it is done in d_func()->syncBackingStore(); this function will sync the backing store of the top level widget, in my case, it will draw the newly exposed area of the widget immediately(in syncBackingStore() Qt will always deem the newly exposed area as dirty even I have called repaint() in my resizeEvent handler). So if I call repaint() in my resizeEvent handler, the newly exposed area will be redrawn twice.

  3. #3
    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: How can I avoid the paintEvent after resizing a widget?

    But why do you want to call repaint() or update() in your resizeEvent at all? It is obvious that a paint event will follow it if necessary. Maybe if you could express what is the purpose of all those manipulations we could suggest a cleaner approach?
    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.


  4. #4
    Join Date
    Sep 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can I avoid the paintEvent after resizing a widget?

    Quote Originally Posted by wysota View Post
    But why do you want to call repaint() or update() in your resizeEvent at all? It is obvious that a paint event will follow it if necessary. Maybe if you could express what is the purpose of all those manipulations we could suggest a cleaner approach?
    Sorry, maybe I don't express my question clearly enough, now I will describe it again:
    As I have mentioned in my first post: I am writing a widget, this widget must refresh all the area after a vertical resizing but only need to refresh the newly visible part after a horizontal resizing( a ruler widget may have the same behaviour).
    1) If I don't set Qt::WA_StaticContents attribute to my widget, Qt will notify me to redraw the entire area of the widget after any kind of resizing. But in the case of horizontal resizing it will waste a lot time to redraw the unchanged part of my widget. I think this is not an effient way.
    2) If I set Qt::WA_StaticContents attribute to my widget, Qt will only notify me to redraw the newly exposed part of my widget after resizing, but in the case of vertical resizing this will make me unable to redraw the entire widget.
    It seems that I have to manually control which part of my widget need to be redrawn in resize event handler by comparing the old size and new size of my widget. I am interested in that is there an elegent way to let me control that by myself?
    Thanks.

  5. #5
    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: How can I avoid the paintEvent after resizing a widget?

    It might prove much easier to cache the looks of your widget and simply rerender the already computed part instead of trying to work around architectures.
    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.


  6. #6
    Join Date
    Sep 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can I avoid the paintEvent after resizing a widget?

    Quote Originally Posted by wysota View Post
    It might prove much easier to cache the looks of your widget and simply rerender the already computed part instead of trying to work around architectures.
    Thanks. I will keep that in mind.

Similar Threads

  1. resizing widgets depending on a main widget size
    By luf in forum Qt Programming
    Replies: 6
    Last Post: 10th October 2009, 16:13
  2. Resize widget force layout resizing
    By ^NyAw^ in forum Qt Programming
    Replies: 17
    Last Post: 11th February 2009, 11:27
  3. Possible to use a widget in another widget's paintEvent?
    By robot_love in forum Qt Programming
    Replies: 2
    Last Post: 9th September 2008, 05:18
  4. resizing events of a custom widget in a layout
    By Rooster in forum Qt Programming
    Replies: 7
    Last Post: 16th February 2008, 10:52
  5. painting a widget outside a paintEvent
    By jayw710 in forum Qt Programming
    Replies: 1
    Last Post: 25th June 2007, 23:18

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.