Results 1 to 5 of 5

Thread: QGraphicsView framework performance

  1. #1
    Join Date
    Jul 2012
    Location
    UK
    Posts
    17
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QGraphicsView framework performance

    Dear All,

    I am using qt 5.0.1 in windows. I am creating 200k+ custom QGraphicsItem. I have added basic functionalists in these custom items, like mouse hover, mouse click etc.. This items are static. But on top of these items I add some items (200 max) which animates (different property animation, scale, opacity etc).
    When I add those items in the scene it become extremely slow, in a relatively powerful workstation.

    Qt Code:
    1. scene->setSceneRect(0, 0, width, height);
    2. scene->setBackgroundBrush(Qt::darkGray);
    3. scene->setItemIndexMethod(QGraphicsScene::NoIndex);
    4.  
    5. QGraphicsView *view = new QGraphicsView( scene );
    6. view->setRenderHint(QPainter::Antialiasing, false);
    7. view->setResizeAnchor(QGraphicsView::AnchorViewCenter);
    8. view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    9. view->resize( width, height );
    10. view->setOptimizationFlags(QGraphicsView::DontSavePainterState);
    11. view->setViewportUpdateMode( QGraphicsView::SmartViewportUpdate);
    12. view->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
    13. view->setCacheMode(QGraphicsView::CacheBackground);
    14. view->setViewportUpdateMode( QGraphicsView::FullViewportUpdate);
    15. view->show();
    To copy to clipboard, switch view to plain text mode 

    I have tried the following, but it makes the rendered view extremely bad, as it seems to enable antialiasing, but I need some pixel label precision.

    Qt Code:
    1. view->setViewport(new QGLWidget( QGLFormat()));
    To copy to clipboard, switch view to plain text mode 


    Am I missing some important Qt programming tricks? Please suggest. I can post the code, or explain more if in case please let me know. Thanks in advance.
    Last edited by saifulkhan; 27th March 2013 at 23:13.

  2. #2
    Join Date
    Jul 2012
    Location
    UK
    Posts
    17
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView framework performance

    May be reducing the frame rate of QPropertyAnimation will help, is there any way to do so?

  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: QGraphicsView framework performance

    It's hard to help without knowing details about your scene. If animating items cover a relatively small portion of the view then I'd disable full viewport update. If "static" items are indeed static and not interactive, I'd replace them with drawBackground. If the scene is not interactive, I'd disable interactivity on the view. I'd also enable caching for the items. That's something to start experimenting with.
    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. The following user says thank you to wysota for this useful post:

    saifulkhan (28th March 2013)

  5. #4
    Join Date
    Jul 2012
    Location
    UK
    Posts
    17
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView framework performance

    Thanks for this nice tricks. Is there any way to set those static custom QGraphicsItems as a background of the view? Currently I add these static items in the same scene where I add those animated items. But for time being I can afford to remove interaction from the static items, though ideally its not the case.

    I have added the following:

    view->setViewportUpdateMode( QGraphicsView::MinimalViewportUpdate );

    Enable item caching: setCacheMode( QGraphicsItem :: DeviceCoordinateCache, bound.size().toSize() );

  6. #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: QGraphicsView framework performance

    Quote Originally Posted by saifulkhan View Post
    Is there any way to set those static custom QGraphicsItems as a background of the view?
    You'd have to draw them yourself. If that's too complex for you then at least enable caching for them.
    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. QGraphicsView and animation framework
    By Diph in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2010, 22:22
  2. QgraphicsView performance
    By nileshsince1980 in forum Qt Programming
    Replies: 2
    Last Post: 15th February 2010, 11:54
  3. again QGraphicsView performance
    By medved6 in forum Qt Programming
    Replies: 11
    Last Post: 21st December 2009, 21:11
  4. QGraphicsView performance in 4.6
    By Lodorot in forum Qt Programming
    Replies: 2
    Last Post: 20th September 2009, 23:09
  5. QGraphicsView Framework coordinate mapping problem
    By zgulser in forum Qt Programming
    Replies: 1
    Last Post: 14th September 2009, 12:30

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.