Results 1 to 4 of 4

Thread: Why must I pad boundingRect() by 7 pixels

  1. #1
    Join Date
    Aug 2009
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Why must I pad boundingRect() by 7 pixels

    Hi,

    I have a clipping/redraw problem with a custom graphicsItem that I draw using the following painter:

    Qt Code:
    1. ypos = xpos = 0;
    2. painter->setPen(Qt::black);
    3. painter->setBrush(Qt::green);
    4. painter->drawLine( width/2, ypos, width/2, height );
    5. painter->drawRect(xpos, ypos, width, height);
    To copy to clipboard, switch view to plain text mode 

    and an overloaded boundingRect call

    Qt Code:
    1. wadjust=7
    2. hadjust=0
    3. return QRectF(xpos,ypos,width+wadjust,height+hadjust);
    To copy to clipboard, switch view to plain text mode 

    I have found that if I pass an object over this graphicsItem (crosshairs in my scene) I get some clipping. If I set the wadjust to 7 (the magic number), I see no clipping. Anything below that I get the clipping but the clipping is fixed by passing the crosshairs back over the object in the opposite direction or by resizing the scene (complete redraw).

    I didn't think the painter pen added width to the drawRect() unless the rectangle was stroked. Any ideas?

    I also remember seeing something in the docs that described how objects are drawn and how the outline pixels are placed around an object but can no longer find that explanation. Anyone know what I'm talking about?

    Thanks.

  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: Why must I pad boundingRect() by 7 pixels

    Could you prepare a minimal compilable example reproducing the problem?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Aug 2009
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why must I pad boundingRect() by 7 pixels

    well it's kind of messy at the moment and it needs to load data to draw the widgets on the scene (2d stock chart). I guess I could try to hack it up but is there anything else I could answer to help?

  4. #4
    Join Date
    Aug 2009
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why must I pad boundingRect() by 7 pixels

    Do you know how many pixels the pen adds to a drawRect?

    painter->pen()->width() returns 0

Similar Threads

  1. Replies: 9
    Last Post: 13th June 2012, 15:42
  2. Updating the boundingRect of a QGraphicsItem
    By robin2000 in forum Qt Programming
    Replies: 4
    Last Post: 14th August 2009, 08:47
  3. boundingRect()?
    By aaron in forum Qt Programming
    Replies: 6
    Last Post: 21st April 2009, 09:43
  4. How to realiably create the boundingRect()
    By zarkzervo in forum Qt Programming
    Replies: 1
    Last Post: 19th February 2009, 13:00
  5. setRect vs boundingRect
    By zgulser in forum Qt Programming
    Replies: 5
    Last Post: 5th February 2009, 00:23

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.