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. Remove QGraphicsItem* from QGraphicsScene, and readd
Forum Updated to NodeBB v4.3 + New Features

Remove QGraphicsItem* from QGraphicsScene, and readd

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 5.1k Views 1 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.
  • L Offline
    L Offline
    LCL_data
    wrote on last edited by
    #1

    I has a QMap<ItemID,QGraphicsItem*> mMap, The number of QGraphicsItem * is more than 1.

    1. I add one QGraphicsItem * named as Item1 into QGraphicsScese using scene->addItem. Item shows correct.
      2.call scene->clear() , and add another QGraphicsItem * named as Item2,Item2 shows correct.
      3.but now , if i readd Item1 into scene, item1 can't show correct. and i found the address of Item1 in mMap had been changed to 0xfeeefeee.

    does the scene->clear() delete the Item1 ?
    how can i do if i want to show these QGraphicsItems more than one time ?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      From the first line of the QGraphicsScene::addItem() docs:
      @
      Adds or moves the item and all its childen to this scene. This scene takes ownership of the item.
      @
      So yes, the scene will delete any item still in it. You want QGraphicsScene::removeItem()

      1 Reply Last reply
      0
      • L Offline
        L Offline
        LCL_data
        wrote on last edited by
        #3

        Thanks for your reply.

        i read the removeItem‘s docs, it should fit my requirement.

        [quote author="ChrisW67" date="1364361826"]From the first line of the QGraphicsScene::addItem() docs:
        @
        Adds or moves the item and all its childen to this scene. This scene takes ownership of the item.
        @
        So yes, the scene will delete any item still in it. You want QGraphicsScene::removeItem()[/quote]

        1 Reply Last reply
        0

        • Login

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