Results 1 to 2 of 2

Thread: How to tell when items are added to or removed from a QGraphicsScene?

  1. #1
    Join Date
    Jan 2012
    Posts
    66
    Thanks
    20
    Thanked 2 Times in 2 Posts
    Platforms
    Windows

    Default How to tell when items are added to or removed from a QGraphicsScene?

    I'd like to know when items are added to or removed from a QGraphicsScene from within the scene. Is there an easy way to do that, or do I have to do it in the constructor and destructor of the QGraphicsItems?

    In particular, I'd like to emit a signal whenever an item is added or removed so that I can use setWindowModified(true) in my QMainWindow.

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

    Default Re: How to tell when items are added to or removed from a QGraphicsScene?

    Constructing an item doesn't mean it gets added to the scene the same as removing items from the scene doesn't mean they get destroyed. You can monitor additions and removals from the scene with QGraphicsItem::itemChange() however since you are the creator of your application you should be able to tell when you add or remove things from the scene. You can restrain yourself from calling QGraphicsScene::add*() methods in favour of exposing a custom scene API that will control when someone adds and removes items from the scene.
    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. The following user says thank you to wysota for this useful post:

    wayfaerer (5th March 2012)

Similar Threads

  1. How to add items in a QGraphicsScene?
    By schmimona in forum Qt Programming
    Replies: 2
    Last Post: 3rd August 2011, 08:53
  2. QListWidget - signal when items are added/removed
    By Andrej08 in forum Qt Programming
    Replies: 1
    Last Post: 19th January 2011, 02:13
  3. Replies: 1
    Last Post: 28th October 2010, 22:36
  4. Replies: 0
    Last Post: 27th July 2010, 12:48
  5. Associate userData to items added to a QListWidget.
    By schall_l in forum Qt Programming
    Replies: 3
    Last Post: 4th August 2009, 12:24

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.