Results 1 to 6 of 6

Thread: setRect vs boundingRect

  1. #1
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default setRect vs boundingRect

    Hi,

    I got confused with the boundingRect. Since setRect sets the coodinate system of the corresponding item, what is boundingRect used for. I mean only setRect seems enough. What is the difference?

    Regards

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: setRect vs boundingRect

    But setRect() is not part of any QGraphicsItem but just QGraphicsRectItem (and QGraphicsEllipseItem) where it makes perfect sense.
    J-P Nurmi

  3. #3
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: setRect vs boundingRect

    Hi again,

    Yeah I mean QGraphicsRectItem or QGraphicsEllipseItem in which setRect method exists. But if we once make item.setRect(...), don't we already have a bounding rect?

    Regards

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: setRect vs boundingRect

    Quote Originally Posted by zgulser View Post
    Yeah I mean QGraphicsRectItem or QGraphicsEllipseItem in which setRect method exists. But if we once make item.setRect(...), don't we already have a bounding rect?
    What do you mean? QGraphicsRectItem uses that rect (adjusted with pen width) as bounding rect. But other items in general don't have any setRect() method. The bounding rect is used by the graphics scene.
    J-P Nurmi

  5. #5
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: setRect vs boundingRect

    More clearly;

    For example, QGraphicsEllipseItem.setRect() = QGraphicsEllipseItem.boundingRect() ?

    Regards

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: setRect vs boundingRect

    Looking at the source code is a good way to answer your question (although J-P has already answered it a couple of times):
    Qt Code:
    1. QRectF QGraphicsRectItem::boundingRect() const
    2. {
    3. Q_D(const QGraphicsRectItem);
    4. if (d->boundingRect.isNull()) {
    5. qreal halfpw = pen().widthF() / 2;
    6. d->boundingRect = d->rect;
    7. if (halfpw > 0.0)
    8. d->boundingRect.adjust(-halfpw, -halfpw, halfpw, halfpw);
    9. }
    10. return d->boundingRect;
    11. }
    To copy to clipboard, switch view to plain text mode 
    Especially take a look at line #6.

    d->rect is set by QGraphicsRectItem::setRect().

Similar Threads

  1. how to set setRect for proxy widget
    By wagmare in forum Qt Programming
    Replies: 0
    Last Post: 23rd November 2008, 13:46
  2. Replies: 1
    Last Post: 31st October 2008, 08:26
  3. QGraphicsItem force boundingRect
    By bunjee in forum Qt Programming
    Replies: 0
    Last Post: 27th September 2008, 16:49
  4. How to avoid calling boundingRect() & shape()
    By nileshsince1980 in forum Qt Programming
    Replies: 7
    Last Post: 8th October 2007, 18:10

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.