Results 1 to 6 of 6

Thread: QGraphics view problem

  1. #1
    Join Date
    Dec 2006
    Posts
    17
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default QGraphics view problem

    Hi guys ,

    I have created an application which contains 100k rectangles and millions of lines.
    In both Qt3.3.6( using QCanvas ) and Qt4.2( using QGraphicsScene).

    The problem with Qt4.2 is scrolling (with scrollbars) which consumes lot of time.But the same thing
    runs smoothly in Qt3.3.6.

    Guys, pls let me know the reason for why it takes lot of time .

    And is there any property, i need to set in QGraphicsView to improve the same.

    Thanks

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

    Default Re: QGraphics view problem

    Can we see the code of the items? What item classes do you use with QGraphicsView? Did you set their shape() and boundingRect() properly?

  3. #3
    Join Date
    Dec 2006
    Posts
    17
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QGraphics view problem

    1.GraphicsLine is derived from QGraphicsItem class and ItemColor (Stores the color of the line)
    2. GraphicsRect is derived from QGraphicsRectItem.

    Bounding rectangle of GraphicsLine is shown below.

    Qt Code:
    1. QRectF GraphicsLine:: boundingRect () const
    2. {
    3. QPolygon p(4);
    4. //Q3PointArray p(poly);
    5. int xi = int(x());
    6. int yi = int(y());
    7. int pw = 1;//pen().width();
    8. int dx = (x1-x2);
    9. if( dx<0)
    10. dx= -dx;
    11. \\ int dy = y1-y2;
    12. if(dy<0)
    13. dy=-dy;
    14. pw = pw*4/3+2; // approx pw*sqrt(2)
    15. int px = x1<x2 ? -pw : pw ;
    16. int py = y1<y2 ? -pw : pw ;
    17. if ( dx && dy && (dx > dy ? (dx*2/dy <= 2) : (dy*2/dx <= 2)) ) {
    18. // steep
    19. if ( px == py ) {
    20. p[0] = QPoint(x1+xi ,y1+yi+py);
    21. p[1] = QPoint(x2+xi-px,y2+yi );
    22. p[2] = QPoint(x2+xi ,y2+yi-py);
    23. p[3] = QPoint(x1+xi+px,y1+yi );
    24. } else {
    25. p[0] = QPoint(x1+xi+px,y1+yi );
    26. p[1] = QPoint(x2+xi ,y2+yi-py);
    27. p[2] = QPoint(x2+xi-px,y2+yi );
    28. p[3] = QPoint(x1+xi ,y1+yi+py);
    29. }
    30. } else if ( dx > dy ) {
    31. // horizontal
    32. p[0] = QPoint(x1+xi+px,y1+yi+py);
    33. p[1] = QPoint(x2+xi-px,y2+yi+py);
    34. p[2] = QPoint(x2+xi-px,y2+yi-py);
    35. p[3] = QPoint(x1+xi+px,y1+yi-py);
    36. } else {
    37. // vertical
    38. p[0] = QPoint(x1+xi+px,y1+yi+py);
    39. p[1] = QPoint(x2+xi+px,y2+yi-py);
    40. p[2] = QPoint(x2+xi-px,y2+yi-py);
    41. p[3] = QPoint(x1+xi-px,y1+yi+py);
    42. }
    43. return p.boundingRect();
    To copy to clipboard, switch view to plain text mode 

    Thanks.
    Last edited by wysota; 6th March 2007 at 10:36. Reason: missing [code] tags

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

    Default Re: QGraphics view problem

    Quote Originally Posted by kiranraj View Post
    1.GraphicsLine is derived from QGraphicsItem class and ItemColor (Stores the color of the line)
    Why not inherit QGraphicsLineItem.

  5. #5
    Join Date
    Dec 2006
    Posts
    17
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QGraphics view problem

    Why not inherit QGraphicsLineItem.

    I created the application to compare the performance ( memory usage and speed)
    b/w QCanvas and QGraphicsView.

    Initially i used QGraphicsLineItem, Since it uses double( Wider than int )to store the co-ordinates
    I didn't prefer it. So i created GraphicsLine, which stores co-ordinates in ints.

    Thanks

  6. #6
    Join Date
    Feb 2007
    Posts
    16
    Thanks
    1
    Platforms
    Windows

    Default Re: QGraphics view problem

    It's probably in double format because that's the format all the calculations should need to be done in. It's possible it has to recast everything on the fly but I'm not sure on that.

    I can't think of any reason they wouldn't give us an overloaded int function, otherwise, since all scene coordinates are effectively integers, anyway.

    I guess it's a precision over memory usage balance since they don't figure anyone will actually put 100's of thousands of polygons in a scene.

    I only put about 9000 in my largest one...

Similar Threads

  1. graphics view FitInView problem
    By aamer4yu in forum Qt Programming
    Replies: 6
    Last Post: 25th January 2007, 10:24
  2. Model, View and Proxy
    By No-Nonsense in forum Qt Programming
    Replies: 2
    Last Post: 21st November 2006, 08:50
  3. problem with tree view
    By boss_bhat in forum Newbie
    Replies: 4
    Last Post: 4th June 2006, 21:03
  4. Replies: 6
    Last Post: 20th April 2006, 10:23
  5. View update problem
    By prakash in forum Qt Programming
    Replies: 6
    Last Post: 17th March 2006, 10:13

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.