Results 1 to 2 of 2

Thread: Resizing QGraphicsView / Repainting QGraphicsItem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Resizing QGraphicsView / Repainting QGraphicsItem

    I have an application containing a QGraphicsView, which in turn views a QGraphicsScene containing a single customized QGraphicsItem. When the user resizes the application's main window, the QGraphicsView, of course, gets resized as well. When this happens, we would like the QGraphicsItem to repaint itself. It already does this, of course.

    The problem is that repainting is inherently slow, involving database lookups and a fair amount of computation before the QGraphicsItem can proceed with painting, a process which can take a few seconds to complete.

    So the problem is: when the QGraphicsView resizes, it sends a steady stream of repaint events down to the QGraphicsItem. This causes an abominable delay while the QGraphicsItem attempts to process all of them.

    There are many solutions to this problem, but what I'd like to is only propagate resize events when the user lets go of the mouse and the window/QGraphicsView/QGraphicsItem are all at their final size, and only then go through the slow repaint calls. Note that mouseRelease events will take place outside the QGraphicsView, when the user is resizing the main application window.

    What is the best way to accomplish this?

  2. #2
    Join Date
    Sep 2008
    Location
    Munich
    Posts
    32
    Thanked 8 Times in 6 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Resizing QGraphicsView / Repainting QGraphicsItem

    Not sure if this works ;-) First of all graphicsview viewport updates are controlled by QGraphicsView::ViewportUpdateMode. Not sure if a set to QGraphicsView::NoViewportUpdate will also prevent updates when resizing. That's one part.

    The other part should be hopefully in QGraphicsView::resizeEvent (or sublcass), where probably a call to update is done to redraw the view. This is something you want to prevent it resize events come in quickly.

    So best maybe is to derive from QGraphicsView and override resizeEvent. There you might want to use QTime, especially the elapsed() method to check if the ui came to rest. If the ui came to rest, you need to call QGraphicsView::reszizeEvent(...)

    Haven't tried it but sounds at least at something you may want to try out ;-) If it works, please post your solution. Thanks

Similar Threads

  1. Repainting a QGraphicsView
    By Luc4 in forum Qt Programming
    Replies: 8
    Last Post: 29th April 2010, 14:09
  2. Very slow repainting ofPixmaps in QGraphicsView images
    By drexiya in forum Qt Programming
    Replies: 3
    Last Post: 21st October 2009, 18:13
  3. QGraphicsView, OpenGL and repainting/updating
    By Amargedon in forum Qt Programming
    Replies: 2
    Last Post: 19th January 2009, 12:03
  4. QGraphicsItem not repainting
    By eijnuhs in forum Qt Programming
    Replies: 3
    Last Post: 20th September 2008, 08:54
  5. Resizing QGraphicsItem
    By philentropist in forum Qt Programming
    Replies: 1
    Last Post: 17th January 2007, 08:28

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.