Results 1 to 2 of 2

Thread: QGraphicsScene of the crime

  1. #1
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QGraphicsScene of the crime

    Hi guys,

    I was trying to add a wdiget on my scene using QGraphicsScene::addWidget() and one of the requirement of the widget to be added is "thou shall not be a child of any widget" . Now my question would be who's gonna clean up when the world ends. I will re-phrase my question "Will the QGraphicsScene own the widget and delete them as they go extinct?

    baray98

  2. #2
    Join Date
    May 2006
    Location
    Germany
    Posts
    108
    Thanks
    2
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene of the crime

    When you use addWidget then you create a QGraphicsProxyWidget. And this is what the docs say on that class:

    QGraphicsProxyWidget shares ownership with QWidget, so if either of the two widgets are destroyed, the other widget will be automatically destroyed as well.
    QGraphicsProxyWidget again is derived from QGraphicsWidget, for which the docs say:

    Although QGraphicsWidget inherits from both QObject and QGraphicsItem, you should use the functions provided by QGraphicsItem, not QObject, to manage the relationships between parent and child items. These functions control the stacking order of items as well as their ownership.

    Note: The QObject:: parent() should always return 0 for QGraphicsWidgets, but this policy is not strictly defined.
    This indicates that your widget is owned by your QGraphicsScene and thus should be destroyed by it.
    "If you lie to the compiler, it will get its revenge." - Henry Spencer

Similar Threads

  1. Replies: 12
    Last Post: 7th September 2011, 16:37
  2. QPaint Class and QGraphicsScene ....I am stuck !!
    By salmanmanekia in forum Qt Programming
    Replies: 7
    Last Post: 30th May 2008, 15:04
  3. QGraphicsScene doesn't accept Drops
    By momesana in forum Qt Programming
    Replies: 5
    Last Post: 15th July 2007, 10:43
  4. QGraphicsScene and QGraphicsView
    By rossd in forum Qt Programming
    Replies: 2
    Last Post: 25th April 2007, 14:43
  5. When to use QGraphicsScene or QWidget
    By fossill in forum Qt Programming
    Replies: 2
    Last Post: 9th February 2007, 23:58

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.