Results 1 to 20 of 80

Thread: GraphicsView performance problems

Threaded View

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

    Default Re: GraphicsView performance problems

    Quote Originally Posted by Gopala Krishna View Post
    I tested with QLine but that didn't make a difference. Also i am not sure what the int cast does - i feel it just takes int part without rounding. But do you think this will make a difference since I am following one convention in all places in drawBackground() ?
    It does make a difference:
    Qt Code:
    1. void drawBackground(QPainter *painter, const QRectF &rect)
    2. {
    3. const int gridSize = 25;
    4.  
    5. const int realLeft = static_cast<int>(std::floor(rect.left()));
    6. const int realRight = static_cast<int>(std::ceil(rect.right()));
    7. const int realTop = static_cast<int>(std::floor(rect.top()));
    8. const int realBottom = static_cast<int>(std::ceil(rect.bottom()));
    9.  
    10.  
    11. const int firstLeftGridLine = realLeft - (realLeft % gridSize);
    12. const int firstTopGridLine = realTop - (realTop % gridSize);
    13.  
    14. QVarLengthArray<QLine, 100> lines;
    15.  
    16. for (int x = firstLeftGridLine; x <= realRight; x += gridSize)
    17. lines.append(QLine(x, realTop, x, realBottom));
    18. for (int y = firstTopGridLine; y <= realBottom; y += gridSize)
    19. lines.append(QLine(realLeft, y, realRight, y));
    20.  
    21.  
    22. painter->setPen(QPen(Qt::darkGreen,0));
    23. painter->drawLines(lines.data(), lines.size());
    24. }
    To copy to clipboard, switch view to plain text mode 

    As you see I make three changes
    a) integer instead of float
    b) using the containing integer rect as basis (i.e. the smallest integer rect that contains the float rect)
    c) I changed the "<" in your for loops to a "<=", i thing part of your corruption was that it did not always repaint the grid when the line was at the border of the exposed rect.


    The result: no more corruption of the grid...only weird color changes that I am trying to track down ;-)


    EDIT: Of course you now need:
    Qt Code:
    1. #include <cmath>
    To copy to clipboard, switch view to plain text mode 
    for the floor, and ceil to work ;-)
    Last edited by camel; 17th February 2007 at 11:34.

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

    Gopala Krishna (17th February 2007)

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.