Results 1 to 4 of 4

Thread: Problem with mapping positions into the scene

  1. #1
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Problem with mapping positions into the scene

    Hi,

    I have a problem with the position of the graphics items in my scene and I don't know how to solve it.

    I have one QGraphicsLineItem on my scene and, when I click on it, it creates a new one. It should draw a horizontal line starting in the last point of the previous item and finishing 30px to the right.

    All of them are childs of biggers QGraphicsItems, pressing a button I enable the user to move those big parent items (moving the childs as well). Some of those objects have two, three or more of the small QGraphicsLineItem.

    So far, I was doing it with:

    Qt Code:
    1. //pseudocode
    2. newItem->setParentItem(parentItem);
    3.  
    4. QPointF prevItemEndingPoint = previousItem.line().p2();
    5. QPointF startingPoint = newItem->mapFromItem(previousItem, prevItemEndingPoint );
    6. QPointF endingPoint = startingPoint;
    7. endingPoint.setX(startingPoint.rx() + 30);
    8.  
    9. newItem.setLine(previousItem, endingPoint);
    To copy to clipboard, switch view to plain text mode 

    It worked fine until now. I've just realized it doesn't work when the I create an item of a different parent and I have moved one the previous parent before, like for instance:





    Now I want to create a new GraphicsItem, so I click in A (pink object is desired, but green is created)



    how I can map those coords? I think I have tried everything...

    thanks!

  2. #2
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: Problem with mapping positions into the scene

    I have one QGraphicsLineItem on my scene and, when I click on it, it creates a new one
    I create an item of a different parent
    Why do you change its parent ? All your GraphicsItem should have the same parent.

    see http://doc.trolltech.com/4.5/graphic...rdinate-system

  3. #3
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Problem with mapping positions into the scene

    Because they are grouped, each parent is a sort of group of other items. So if you press a button the parent is shown, the childs are hidden and you can move that group and only that group and its elements.

    QGraphicsItemGroup is not an option because the parent is a "QGraphicsPathItem" (it has to be this way)

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

    Default Re: Problem with mapping positions into the scene

    Quote Originally Posted by jano_alex_es View Post
    Because they are grouped, each parent is a sort of group of other items. So if you press a button the parent is shown, the childs are hidden and you can move that group and only that group and its elements.

    QGraphicsItemGroup is not an option because the parent is a "QGraphicsPathItem" (it has to be this way)
    You can group items not only using a parent-child relationship. In your situation I'd advise to have all items within the same parent as well. Just make the "group item" hold pointers to all its members and when the group item moves, move the members along. Otherwise you'll be constantly recalculating relative positions of items which I see is hard for you to cope with.
    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.


Similar Threads

  1. QGraphicsView Framework coordinate mapping problem
    By zgulser in forum Qt Programming
    Replies: 1
    Last Post: 14th September 2009, 12:30
  2. Mouse mapping on QTransform problem
    By captchaq in forum Newbie
    Replies: 2
    Last Post: 26th September 2008, 19:11
  3. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  4. Creating new scene from a part of an old one
    By maverick_pol in forum Qt Programming
    Replies: 6
    Last Post: 28th November 2007, 18:14
  5. Creating a scene from piece of another scene
    By maverick_pol in forum Qt Programming
    Replies: 3
    Last Post: 23rd August 2007, 17:51

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
  •  
Qt is a trademark of The Qt Company.