Results 1 to 4 of 4

Thread: Can I copy a QGraphicsItem on my scene?

  1. #1
    Join Date
    Dec 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Can I copy a QGraphicsItem on my scene?

    I have a nice looking class inherited from QGraphicsItem that I use on my scene. Let's call an object of that class A

    Some other items (B and C) of another class can have pointers (in the graphical sense, not the variable memory sense!) to A. I show this by drawing an arrow from B to A and from C to A, sort of like this:

    B -> A <- C

    When B and C are a long distance from each other I would like to instantiate another copy of A so that I can draw something like:


    B->A


    C->A



    ...but A can only be added once to the scene.

    What is the smart way of solving this without making two copies of A that have to be modified simultaneously if they change?

  2. #2
    Join Date
    Oct 2009
    Location
    Mexico
    Posts
    81
    Thanks
    6
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Can I copy a QGraphicsItem on my scene?

    i don´t know the context of the aplication...
    but if you need the three item show in scene A, B and C.

    - adjust the scale factor in the view to show the 3 items (easy way)
    - change the position of the item A if B and C are long distance from each other

    if you choose the option 2, you need reimplement the QGraphicsItem::itemChange() function to detect when a item change your position (in item B and C) and if the distance between B and C are big enough, change the position of item A.
    Last edited by ecanela; 11th February 2010 at 00:12.

  3. #3
    Join Date
    Dec 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can I copy a QGraphicsItem on my scene?

    Well... that was a question I didn't ask :-)
    I must have been unclear...

    The question is: How can I display the same QGraphicsItem in two different locations of my scene?

  4. #4
    Join Date
    Oct 2009
    Location
    Mexico
    Posts
    81
    Thanks
    6
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Can I copy a QGraphicsItem on my scene?

    i don't think is posible display the same item in two diferent location. because each item have only one position QGraphicsItem::pos() in the scene.

    try to use QGraphicsItemGroup class. this classs treat a group if tem as one item.
    Last edited by ecanela; 13th February 2010 at 02:30.

Similar Threads

  1. Copy and Paste of QGraphicsItems in a Scene
    By subash in forum Qt Programming
    Replies: 6
    Last Post: 6th July 2011, 15:15
  2. QGraphicsItem .. Scene .. View question?
    By DirtyBrush in forum Qt Programming
    Replies: 21
    Last Post: 19th October 2010, 09:12
  3. Update scene after moving QGraphicsItem
    By rogerholmes in forum Newbie
    Replies: 1
    Last Post: 19th January 2010, 05:08
  4. Deleting a scene from QGraphicsItem mouseEvent
    By JonathanForQT4 in forum Qt Programming
    Replies: 5
    Last Post: 10th April 2007, 11:27
  5. Replies: 1
    Last Post: 26th September 2006, 05:38

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.