Results 1 to 6 of 6

Thread: Scaling too much on a graphics view

  1. #1
    Join Date
    Sep 2009
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Scaling too much on a graphics view

    I build a huge maps with lots of polygons,texts and stuff.
    Now, I'd like to be able to zoom lots of time without any limits.

    To be clear I should be able to look at,let's say, a port closely on a Europe Map.
    However, after some scale commands of GraphicsView, it starts to slow down and then freezes.

    I'm guessing after some scaling, polygons of European lands become too large and drawing or creating them consumes too much CPU.

    Is there a solution for this kind of thing in Qt (like cache mode - I tried -,x mode etc..) or do I have to find a workaround for this?

    If workaround, can you suggest something? Screen will be interactive, so pixmap stuff doesn't seem to be a solution. Drawing that part of the map again is also not a complete solution, because intersecting polygons doesn't do a great job.

    Thank you.

    Trivial question : Subtracting small(doesn't matter though) polygons from huge polygons with thousands of points... This action sometimes takes several seconds,and I need to do this lots of times. Right now, I'm painting small polygons onto huge polygons but I'm not sure it's safe in the long run. Again, any workaround or fix?

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Scaling too much on a graphics view

    See QPixmapCache and .
    If I compare the functionality of your application with google maps.
    Google uses manual caching, means google doesn't keeps full image in memory coz that is expensive and in a map application caching is most important feature. So keep the image in memory what is visible and very near to that. You need to unload the part of the image which is not comes withing current view port.
    Good Luck !

  3. #3
    Join Date
    Sep 2009
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Scaling too much on a graphics view

    The problem is I can't use QPixmap or image like google map does. I have to use QGraphicsPolygonItem kind of things because next step in my project will be making them clickable and interactive.
    thanks to the graphics view, even though I scale like crazy, the image I don't see is cached(?). So, there isn't any problem with memory.
    Last edited by natnan; 15th September 2009 at 12:36.

  4. #4
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Scaling too much on a graphics view

    So for further enhancement can play with :
    Qt Code:
    1. QGraphicsView::OptimizationFlags
    2. QGraphicsView::CacheModeFlag
    3. QGraphicsView::ViewportUpdateMode
    To copy to clipboard, switch view to plain text mode 

    QGraphicsView::MinimalViewportUpdate
    This is proven to be best performance booster.

  5. The following user says thank you to yogeshgokul for this useful post:

    natnan (15th September 2009)

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

    Default Re: Scaling too much on a graphics view

    I see. Although those are useful boosts, that's not the solution I'm looking for.
    thanks.

  7. #6
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Scaling too much on a graphics view

    I am using QGraphicsView and the best optimization I have found is to write my own QGraphicsItem.

    For instance, I manage multi resolution huge images, and I overloaded the paintEvent of a QGraphicsItem derived like this :

    Qt Code:
    1. void QGraphicsItemResource::paint(QPainter * painter,
    2. const QStyleOptionGraphicsItem * options,
    3. QWidget *) {
    4. painter->setClipping(true);
    5. painter->setClipRect(options->exposedRect);
    6. painter->drawImage(options->exposedRect, sourceImage, sourceRect);
    7. }
    To copy to clipboard, switch view to plain text mode 

    The thing I want to point out is the use of QPainter::drawImage, that prevent from QPixmap copies and do the scaling automatically during the paint. So the performances are better.

    And if you are not using image, but only polygons, try to enable Clipping top minimize painting operation. Another solution is to simplify the geometry according to the scale displayed defore painting the item. In all cases, you will need to implement your own QGraphicsItem.

    S.Cascio

Similar Threads

  1. Graphics View and the Pixmap
    By spawn9997 in forum Qt Programming
    Replies: 2
    Last Post: 26th June 2009, 22:12
  2. Graphics View Panning ,zooming
    By linuxdev in forum Qt Programming
    Replies: 3
    Last Post: 29th December 2008, 07:17
  3. Replies: 4
    Last Post: 5th August 2008, 19:55
  4. Graphics View Event Propagation
    By pherthyl in forum Qt Programming
    Replies: 10
    Last Post: 3rd July 2008, 10:39
  5. Graphics view display problem.
    By kiranraj in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2007, 07:08

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.