Results 1 to 20 of 80

Thread: GraphicsView performance problems

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    128
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 28 Times in 27 Posts

    Default Re: GraphicsView performance problems

    just a note:
    If you like to profile further into the drawing part,
    you need to call:
    valgrind --tool=callgrind --seperate-callers=5 --seperate-recs=10 ./YOUR_APP
    Otherwise you will get "cycles", which is not very helpfull in this task..

    BUT: this takes up much more memory to analyze later...

  2. #2
    Join Date
    Jan 2006
    Posts
    128
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 28 Times in 27 Posts

    Default Re: GraphicsView performance problems

    Hi,

    well I just love to play with this... ;-)


    Here is another (and much faster) way to write the drawBackground function...with the added niceness that it helps avoiding the color errors ;-)

    You might want to check if this survives zooming etc.

    Qt Code:
    1. void drawBackground(QPainter *painter, const QRectF &rect)
    2. {
    3. const int gridSize = 25;
    4.  
    5. if (backgroundCache.isNull()) {
    6. backgroundCache = QPixmap(gridSize, gridSize);
    7. const int middle = gridSize / 2;
    8. QPainter backgroundPainter(&backgroundCache);
    9. backgroundPainter.setRenderHints(painter->renderHints());
    10. backgroundPainter.fillRect(QRect(0, 0, gridSize, gridSize), QBrush(Qt::white));
    11. backgroundPainter.setPen(backgroundPen);
    12. backgroundPainter.setBrush(backgroundBrush);
    13. backgroundPainter.drawLine(0, middle, gridSize, middle);
    14. backgroundPainter.drawLine(middle, 0, middle, gridSize);
    15. }
    16.  
    17. const int realLeft = static_cast<int>(std::floor(rect.left()));
    18. const int realRight = static_cast<int>(std::ceil(rect.right()));
    19. const int realTop = static_cast<int>(std::floor(rect.top()));
    20. const int realBottom = static_cast<int>(std::ceil(rect.bottom()));
    21.  
    22.  
    23. const int firstLeftGridLine = realLeft - (realLeft % gridSize);
    24. const int firstTopGridLine = realTop - (realTop % gridSize);
    25.  
    26.  
    27. QPainterPath background;
    28. for (int x = firstLeftGridLine; x < realRight; x += gridSize) {
    29. for (int y = firstTopGridLine; y < realBottom; y += gridSize) {
    30. painter->drawPixmap(x, y, backgroundCache);
    31. }
    32. }
    33. }
    To copy to clipboard, switch view to plain text mode 

    Have a nice day :-)
    Last edited by camel; 17th February 2007 at 16:26.

  3. The following user says thank you to camel for this useful post:

    Gopala Krishna (17th February 2007)

  4. #3
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    37
    Thanked 53 Times in 40 Posts

    Default Re: GraphicsView performance problems

    Quote Originally Posted by camel View Post
    Hi,

    well I just love to play with this... ;-)


    Here is another way to write the drawBackground function...with the added niceness that it helps avoiding the color errors ;-)

    You might want to check if this survives zooming etc.

    Qt Code:
    1. void drawBackground(QPainter *painter, const QRectF &rect)
    2. ...
    To copy to clipboard, switch view to plain text mode 

    Have a nice day :-)
    Not bad idea! That problem solved !!! Thanks a lot.
    Now the next problem is performance !
    A good day to you too
    Last edited by Gopala Krishna; 17th February 2007 at 16:32. Reason: updated contents
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  5. #4
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    37
    Thanked 53 Times in 40 Posts

    Default Re: GraphicsView performance problems

    Quote Originally Posted by camel View Post
    just a note:
    If you like to profile further into the drawing part,
    you need to call:


    Otherwise you will get "cycles", which is not very helpfull in this task..

    BUT: this takes up much more memory to analyze later...
    I get the following error
    valgrind: Bad option '--seperate-callers=5'; aborting.
    I am trying to analyse the code as it is now. I am getting lost here and there but kcachegrind is a cool tool. Needs some time to get used to it. Thanks for helping me till now. I'll continue with this tomorrow.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  6. #5
    Join Date
    Jan 2006
    Posts
    128
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 28 Times in 27 Posts

    Default Re: GraphicsView performance problems

    Quote Originally Posted by Gopala Krishna View Post
    I get the following error
    valgrind: Bad option '--seperate-callers=5'; aborting.
    I think they changed the option names during 3.1 and 3.2 (which I use)

    try:
    valgrind --tool=callgrind --fn-caller=5 --fn-recursion=10 ./YOUR_APP

Similar Threads

  1. Performance problems with overlapping qgraphicsitems
    By brjames in forum Qt Programming
    Replies: 13
    Last Post: 4th May 2008, 21:42
  2. QT GraphicsView Help
    By mistertoony in forum Qt Programming
    Replies: 15
    Last Post: 15th February 2007, 04:17
  3. Replies: 1
    Last Post: 4th October 2006, 16:05
  4. QT4 Plugins - problems, problems
    By NormanDunbar in forum Qt Programming
    Replies: 6
    Last Post: 9th May 2006, 15:39
  5. Increasing performance from Qtextedit, listview, etc?
    By taylor34 in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2006, 10:20

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.