Results 1 to 5 of 5

Thread: Updating the boundingRect of a QGraphicsItem

  1. #1
    Join Date
    Aug 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Updating the boundingRect of a QGraphicsItem

    hi,

    i have a QGraphicsItemGroup with several items in it. The boundingRect is computed correctly according to the current boundingRects of the group members. Now i change the size of one member in the group, so that his boundingRect exceeds the group's boundingRect.
    But when I call group.boundingRect(), it was not updated. Is there any way to manually update the boundingRect of an existing item group? Even implementing an inherited version of boundingRect() in a child class of QGraphicsItemGroup does not work, because boundingRect in QGraphicsItemGroup is not virtual thus the graphics engine would only call the ancestors version, when treating the object as a QGraphicsItem.
    The only workaround i found is to remove an item from the group and adding it again, because then the boundingRect stored in the private variable d->itemsBoundingRect is updated. But that can't be the solution.

    I'd be grateful for any ideas.

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

    Default Re: Updating the boundingRect of a QGraphicsItem

    Sure it's virtual...
    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
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Updating the boundingRect of a QGraphicsItem

    No, boundingRect() is only virtual in QGraphicsItem not in QGraphicsItemGroup. Here is the code from the implementation:
    Qt Code:
    1. /*!
    2.   \reimp
    3.  
    4.   Returns the bounding rect of this group item, and all its children.
    5. */
    6. QRectF QGraphicsItemGroup::boundingRect() const
    7. {
    8. Q_D(const QGraphicsItemGroup);
    9. return d->itemsBoundingRect;
    10. }
    To copy to clipboard, switch view to plain text mode 

    and the declaration in class QGraphicsItemGroup:
    Qt Code:
    1. 1062 QRectF boundingRect() const;
    To copy to clipboard, switch view to plain text mode 
    Last edited by robin2000; 14th August 2009 at 08:37.

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

    Default Re: Updating the boundingRect of a QGraphicsItem

    Qt Code:
    1. #include <iostream>
    2. class A {
    3. public:
    4. virtual void function() { std::cout << "A" << std::endl; }
    5. };
    6.  
    7. class B : public A {
    8. public:
    9. void function() { std::cout << "B" << std::endl; }
    10. };
    11.  
    12. class C : public B {
    13. void function() { std::cout << "C" << std::endl; }
    14. };
    15.  
    16. int main(){
    17. A *obj = new A;
    18. obj->function();
    19. delete obj;
    20. obj = new B;
    21. obj->function();
    22. delete obj;
    23. obj = new C;
    24. obj->function();
    25. delete obj;
    26. return 0;
    27. }
    To copy to clipboard, switch view to plain text mode 
    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.


  5. #5
    Join Date
    Aug 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: Updating the boundingRect of a QGraphicsItem

    Your so right. It didn't work in my case, because I tried to call QGraphicsItemGroup.boundingRect() instead of QGraphicsItem.boundingRect(). But that's easy to solve now.

    Thank you very much for your fast help. Learned something about inheritance

Similar Threads

  1. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 10:31
  2. boundingRect()?
    By aaron in forum Qt Programming
    Replies: 6
    Last Post: 21st April 2009, 09:43
  3. Replies: 1
    Last Post: 25th February 2009, 00:34
  4. QGraphicsItem force boundingRect
    By bunjee in forum Qt Programming
    Replies: 0
    Last Post: 27th September 2008, 16:49
  5. QGraphicsItem -> boundingRect()
    By harakiri in forum Qt Programming
    Replies: 4
    Last Post: 6th March 2008, 15:02

Tags for this Thread

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.