Results 1 to 5 of 5

Thread: problem about drawRect

  1. #1
    Join Date
    Jun 2006
    Location
    Vietnam
    Posts
    59
    Thanks
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default problem about drawRect

    I don't understand about drawRect. Please see this example:

    Qt Code:
    1. void MyWidget:: paintEvent(QPaintEvent *e)
    2. {
    3. QPainter p(this);
    4. QRect r = QRect(100, 100, 400, 400);
    5. p.setPen(Qt::red);
    6. p.drawRect(r);
    7.  
    8. int x1, y1, x2, y2);
    9. r.getCoords(&x1, &y1, &x2, &y2); // it will return x1=100, y1=100, x2=499, y2=499
    10. p.setPen(Qt::green);
    11. p.drawLine(x1, y1, x2, y1);
    12. p.drawLine(x2, y1, x2, y2);
    13. p.drawLine(x1, y2, x2, y2);
    14. p.drawLine(x1, y1, x1, y2);
    15. }
    To copy to clipboard, switch view to plain text mode 

    Please tell me why 2 rectangle not overlap? I really not understand about the meaning of drawRect function.

  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: problem about drawRect

    Are you asking why there is 499 instead of 500 or why there is 499 instead of 400?

  3. #3
    Join Date
    Jun 2006
    Location
    Vietnam
    Posts
    59
    Thanks
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem about drawRect

    I understand why 499 instead of 500. My problem is that why the function drawRect don't draw a rectangle (100, 100, 400, 400) begin from (100, 100) to (499, 499), but in this case this rectangle draw from (100, 100) to (500, 500).

    Because I always think both of solutions will give 2 rectangles overlap together.
    Thanks.

  4. #4
    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: problem about drawRect

    Could you restate the problem? What do you mean by "overlap"? That they intersect or that they have exactly the same coordinates or all four corners?

    Qt Code:
    1. drawRect(QRect(100,100,400,400));
    To copy to clipboard, switch view to plain text mode 
    will draw a rectangle beginning in point (100,100) and having a width of 400 and height of 400. So the bottom right corner will have coordinates of (499,499). drawLine() and drawRect() may interpret the pen width differently (I'm not sure of that, but it's a good guess the rect version would draw it's line half the pen width to the inside (left and up in this case) than drawLine).

  5. The following user says thank you to wysota for this useful post:

    vql (29th April 2008)

  6. #5
    Join Date
    Jun 2006
    Location
    Vietnam
    Posts
    59
    Thanks
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem about drawRect

    Good. Thank you too much.
    But why drawLine() and drawRect() may interpret the pen width differently?

Similar Threads

  1. problem with paint and erase in frame
    By M.A.M in forum Qt Programming
    Replies: 9
    Last Post: 4th May 2008, 20:17
  2. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35
  3. Graphics view display problem.
    By kiranraj in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2007, 07:08
  4. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.