Results 1 to 11 of 11

Thread: QGraphicsView performance problems

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    2

    Default Re: QGraphicsView performance problems

    I added:
    Qt Code:
    1. qglwidget = new QGLWidget;
    2. qglwidget->context()->format().setDoubleBuffer(true);
    3. setViewport(qglwidget);
    To copy to clipboard, switch view to plain text mode 
    to the initalization code given above, but without any positive outcome.
    (I hope I did it correctly)

  2. #2
    Join Date
    May 2010
    Location
    Russia
    Posts
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanked 1 Time in 1 Post

    Default Re: QGraphicsView performance problems

    Quote Originally Posted by MarPan View Post
    I added:
    Qt Code:
    1. qglwidget = new QGLWidget;
    2. qglwidget->context()->format().setDoubleBuffer(true);
    3. setViewport(qglwidget);
    To copy to clipboard, switch view to plain text mode 
    to the initalization code given above, but without any positive outcome.
    (I hope I did it correctly)
    I hope, In this case you don't use QGraphicsScene and QGraphicsView for painting object's? you should use
    Qt Code:
    1. void GLWidget::paintEvent(QPaintEvent *event)
    To copy to clipboard, switch view to plain text mode 
    for manually painting objects (without QGraphicsScene, QGraphicsView classes).
    Rendering with using only QtOpengGl must give more efficiency then using graphics scene.
    Last edited by xray2000; 2nd July 2010 at 07:02.

  3. #3
    Join Date
    Jun 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    2

    Default Re: QGraphicsView performance problems

    Firstly, I may have misinformed you. When I wrote
    I commented out code from mouse::advance that was checking for collisions
    I was right, but there was also one line in paint(), that was resposible for color of ears if there was a collision.

    So right now, instead of drawing a mouse, I load a pixmap from disk (it's just a 25x50 monocolored rectangle) and store a pointer inside a mouse class. In the paint function I have
    Qt Code:
    1. painter->setClipRect( option->exposedRect );
    2. pixmap->fill(scene()->collidingItems(this).isEmpty() ? Qt::cyan : Qt::red);
    3. painter->drawPixmap(pixmap->rect(), *pixmap, pixmap->rect());
    To copy to clipboard, switch view to plain text mode 
    With code like this, the maximum is about 60 "cars". When I comment the middle line, I can have over 200 without significant slowdown.

    So it apperas it's collision after all. But documentation says I can have "millions of items on the scene". Am I doing something wrong?
    Of course I set the ItemIndexMethod back to QGraphicsScene::BspTreeIndex. I also left viewport set to opengl with double buffering on, since it helped a little (though I don't know why).

    And I don't really want to give up on qgraphicsview. The reason I chose it was because of it's collision tools.


    EDIT: I just have read an interesting blog entry: http://labs.trolltech.com/blogs/2009...een-rendering/. Andreas also tried improving performance of colliding mice and says
    (the bottleneck of the example becomes the collision-detection)
    . Does that mean that I cannot go any further than that?
    Last edited by MarPan; 2nd July 2010 at 10:42. Reason: updated contents

  4. #4
    Join Date
    Aug 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: QGraphicsView performance problems

    Sorry to bump an oldish thread, but I've noticed similar performance issues with QGraphicsScene and collision detection, particularly when running on my Nokia 5800 (Symbian).

    I have written a simple breakout clone. There are around 27 items in the scene. When I call QGraphicsScene::collidingItems once per frame (to check for collisions between ball and blocks), performance is fine.

    I then added a bonus where the player could shoot bullets, and for each bullet, there was an additional call to QGraphicsScene::collidingItems. There was a noticable slowdown with each bullet added, with it slowing to a crawl even with only 2-3 bullets!

    I fixed the problem by writing my own spatial indexing method, implementing a 2D spatial grid. Now sure, obviously I realise that an indexing method written specifically for my game will do better than a generic indexing method, but I don't understand why it's so slow. The documentation says "One of QGraphicsScene's greatest strengths is its ability to efficiently determine the location of items. Even with millions of items on the scene, the items() functions can determine the location of an item within few milliseconds."

    My blocks are static, so I don't think that's a problem for the BSP. Also I note that things seem to run just as slowly with BSP indexing, compared with indexing disabled.

    I don't know if this is normal behaviour, or we're doing something wrong?

Similar Threads

  1. QgraphicsView performance
    By nileshsince1980 in forum Qt Programming
    Replies: 2
    Last Post: 15th February 2010, 11:54
  2. again QGraphicsView performance
    By medved6 in forum Qt Programming
    Replies: 11
    Last Post: 21st December 2009, 21:11
  3. QGraphicsView performance in 4.6
    By Lodorot in forum Qt Programming
    Replies: 2
    Last Post: 20th September 2009, 23:09
  4. QGraphicsView performance
    By Halabund in forum Newbie
    Replies: 3
    Last Post: 17th April 2009, 10:12
  5. QGraphicsScene/QGraphicsView performance problems
    By bnilsson in forum Qt Programming
    Replies: 71
    Last Post: 28th January 2008, 12: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
  •  
Qt is a trademark of The Qt Company.