Results 1 to 6 of 6

Thread: QGraphics view problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #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

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
  •  
Qt is a trademark of The Qt Company.