Results 1 to 3 of 3

Thread: QGraphicsView and QGraphicsScene speeds

  1. #1
    Join Date
    Feb 2006
    Posts
    21
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QGraphicsView and QGraphicsScene speeds

    Hello all,

    I am using QGraphicsView and QGraphicsScene to display thousands of points from a database.

    Collecting the points from the database takes about 2 seconds but when i try to display them on a scene by using:

    QGraphicsItem *item = new QGraphicsRectItem (x,y,1,1);
    SampleScene->addItem(item);

    it takes about 10 seconds to load the rectangles and then when i move the scene in the view it is very sluggish and takes a while to refresh.

    Any ideas on making this faster to display?
    Any hints or tips on using QGraphicsView to it's maximum potential?

    John

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsView and QGraphicsScene speeds

    If you could post your code here, it would be easier to solve your problem. The 40000 chips demo loads 40000 items almost instantly and handles them real time in four views, so unless you are using more than millions of items, it shouldn't be sluggish (when run on a decent machine, of course).

  3. #3
    Join Date
    Feb 2006
    Posts
    21
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView and QGraphicsScene speeds

    Ok I have a dialog with a QGraphicsView inside.
    In my header i have QGraphicsScene *SampleScene;

    Qt Code:
    1. SampleScene = new QGraphicsScene;
    2.  
    3. query.exec( "SELECT x,y FROM samples;" );
    4.  
    5. while( query.next() )
    6. {
    7. ( minX - query.value(0).toDouble() ) * -scaleX, ( maxY - query.value(1).toDouble() ) * scaleY, 5, 5 );
    8.  
    9. SampleScene->addItem(item);
    10. }
    11.  
    12. ui.graphicsView->setRenderHints( QPainter::Antialiasing );
    13. ui.graphicsView->setScene(SampleScene);
    To copy to clipboard, switch view to plain text mode 

    I would prefer dots rather than squares and should be easier to draw. I have tried ui.graphicsView->setUpdatesEnabled(false) which helped slightly but still is very slow. I have also tried QGraphicItemsGroup which I have yet to get working for some reason. I would put the items into a QList of QGraphicItems and then
    Qt Code:
    1. SampleGroup = SampleScene->createItemGroup ( list );
    2. SampleGroup->show();
    To copy to clipboard, switch view to plain text mode 

    But I could never see the points. I have studied the 40000 chips example and have also implemented a custom QGraphicsItem which helped slightly in speed. Everything else looks similar to the chips example but much slower.

Similar Threads

  1. (QT4.2-RC1) QGraphicsScene QGraphicsView QGraphicsItem
    By antonio.r.tome in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 11:56

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.