Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Does every QGraphicsItem need to be QGraphicsScene's child?

Does every QGraphicsItem need to be QGraphicsScene's child?

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 868 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • clostridium_difficileC Offline
    clostridium_difficileC Offline
    clostridium_difficile
    wrote on last edited by clostridium_difficile
    #1

    I am developing Raster Graphics Editor. I am confused because I have read that QGraphicsScene's addItem() method adds QGraphicsItem, and all it's children, to scene, but in other forums people says that every item needs to be added to scene apart from other, parent QGraphicsItem. What is the correct approach? Other question: how to remove/detach child graphics item from it's parent? If QGraphicsItem was created by new operator, then set parent to other graphics item, who is responsible for freeing memory? Does QGraphicsItem's destructor invokes delete operator for every child (if at all)?

    A 1 Reply Last reply
    0
    • clostridium_difficileC clostridium_difficile

      I am developing Raster Graphics Editor. I am confused because I have read that QGraphicsScene's addItem() method adds QGraphicsItem, and all it's children, to scene, but in other forums people says that every item needs to be added to scene apart from other, parent QGraphicsItem. What is the correct approach? Other question: how to remove/detach child graphics item from it's parent? If QGraphicsItem was created by new operator, then set parent to other graphics item, who is responsible for freeing memory? Does QGraphicsItem's destructor invokes delete operator for every child (if at all)?

      A Offline
      A Offline
      Asperamanca
      wrote on last edited by Asperamanca
      #2

      @clostridium_difficile

      1. You either add an item to a scene directly, OR use setParentItem to set it's parent. It will then automatically be added to the scene of that parent.
      2. As soon as an item has a scene or parent, that scene or parent is its owner. When the scene is destroyed, all items belonging to that scene are destroyed. When a parent item is destroyed, all it's children are destroyed.
      3. You can always change an item's parent or scene later on
      4. Never use "setParent" on GraphicsItems that also happen to be QObjects! Always stick to setParentItem!
      1 Reply Last reply
      3

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved