Results 1 to 4 of 4

Thread: How does QGraphicsItem::prepareGeometryChange() work?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How does QGraphicsItem::prepareGeometryChange() work?

    Quote Originally Posted by wayfaerer View Post
    Does "before" mean *right* before? Any time before?
    Any time after you know the rect is going to change and before you relinquish control of the flow to the event loop.

    Does this mean I don't need to call update()?
    Correct.

    Say I have a QGraphicsItem subclass whose boundingRect() function returns a rectangle that is a static class member.
    A very odd situation.

    If I want update the static rectangle, do I have to call prepareGeometryChange() on every instance of the class, update the static rectangle, and then call update() on every instance?
    You just need to update the static variable and call prepareGeometryChange() on every instance of the class.

    Quote Originally Posted by wayfaerer View Post
    What I don't understand is how the scene knows the bounding rectangle has changed, since there is no setter for the bounding rect, only a getter.
    It calls boundingRect(). That's why prepareGeometryChange() is required -- it essentially tells graphics view to remove any cached values regarding the size of the object and requery them from the object again.

    Does this mean that after you call prepareGeometryChange() the scene begins polling for changes, by calling QGraphicsItem::boundingRect() and comparing that one with what it has stored?
    Basically yes.

    Does this mean that QGraphicsScene only polls for a change right before control goes back to the event loop (and of course, only if prepareGeometryChange() has been called)?
    The scene updates its structures when it decides they need updating. A rule of thumb is that it will happen when some event regarding the scene is being processed.
    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.


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

    wayfaerer (2nd May 2012)

Similar Threads

  1. Subclassing QGraphicsItem to work as a layer
    By kefir in forum Qt Programming
    Replies: 7
    Last Post: 10th March 2011, 09:42
  2. Why QGLFramebufferObject in QGraphicsItem don’t work?
    By Student3000 in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2010, 20:12
  3. QGraphicsItem::setToolTip does not work
    By Nadia in forum Qt Programming
    Replies: 2
    Last Post: 6th September 2009, 19:54
  4. Replies: 5
    Last Post: 17th February 2009, 04:35
  5. prepareGeometryChange problem
    By stefan in forum Qt Programming
    Replies: 2
    Last Post: 10th August 2008, 09:30

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