Results 1 to 3 of 3

Thread: QGraphicsItem.setPos takes a lot of time

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2009
    Location
    Russia, Saint-Petersburg
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QGraphicsItem.setPos takes a lot of time

    Hi
    I read in documentation to the Graphics View Framework that visualization of even millions of items performs real-time. To check it I put a little experiment. I made just 50000 items of QGraphicsEllipseItem(qrand() % 500, qrand() % 500, 4, 4) and tried to move it chaotically every half of a second. QGLWidget was selected as viewport. Code of the move() slot to the timer's timeout() signal looked like this:

    Qt Code:
    1. void Visview::move()
    2. {
    3. for (int i = 0; i < 50000; i++)
    4. {
    5. elems[i]->setPos(elems[i]->x() + (qrand() % 20) - 10,
    6. elems[i]->y() + (qrand() % 20) - 10);
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    For timer timeout=500 ms it worked extremely slow: about 20 secs to one step of movement. I achieved a big performance improvement by adding

    Qt Code:
    1. scene.update(-500, -500, 1000, 1000);
    To copy to clipboard, switch view to plain text mode 

    to the end of the function. But speed of working is still unsatisfactory to me. About 1.5-2 secs to step, and about 8 secs to first step of movement. I found that the loop with new positions setting

    Qt Code:
    1. for (int i = 0; i < 50000; i++)
    2. {
    3. elems[i]->setPos(elems[i]->x() + (qrand() % 20) - 10,
    4. elems[i]->y() + (qrand() % 20) - 10);
    5. }
    To copy to clipboard, switch view to plain text mode 

    takes about 600 ms to step. Can I make this loop faster somehow?

    PS. I learned source code of the setPos and found it call update function of the scene. But if internal flag updateAll is set to true update() does nothing. To set updateAll to true it's enough to call scene.update(QRect()). I tried to do so before loop, but it took no effect.

    My Qt version is 4.6.0.

    Thank you.
    Last edited by ricofe25; 8th December 2009 at 17:07.

Similar Threads

  1. QTextEdit loading takes long time
    By sreedhar in forum Qt Programming
    Replies: 12
    Last Post: 21st March 2011, 10:29
  2. Replies: 4
    Last Post: 3rd August 2009, 20:25
  3. Replies: 1
    Last Post: 1st February 2008, 18:55
  4. QDateTime GMT add sec. or - sec. from locale time....
    By patrik08 in forum Qt Programming
    Replies: 2
    Last Post: 20th February 2007, 16:39
  5. Problem with pointers while using localtime() and time()
    By jamadagni in forum General Programming
    Replies: 7
    Last Post: 11th January 2006, 15:48

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.