Results 1 to 2 of 2

Thread: Handling Objects coordinates related to another object.

  1. #1
    Join Date
    Mar 2011
    Posts
    82
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Handling Objects coordinates related to another object.

    So ...

    I need to create objects and position them in direct relation to a certain object already in the scene. In fact, this item is a parent of said new item-to-be-created.

    I have this:

    A dialog window.
    a scene object.
    a view view object.
    a parent object.
    many child objects.

    I want each child I create to use its parameters (ones that I pass to it when instantiated) and create itself taking as 0,0 the parent object's 0,0, not the scene's 0,0.

    Example;
    I have a parent Square drawn at (4,4, 1000, 1000). Now I want instantiate new items, childs, and if I pass a (2, 2, 10, 10) as parametere, to have it be drawn in what would be (4 + 2, 4 + 2, 10, 10) from a scenes perspective or just (2, 2, 10, 10) from the parent's perspective.

    I'm trying to do something like

    parent = new QGraphcisItem();
    child = new QGraphicsItem();

    child->setParentItem(parent);

    the thing is, now I don't know how to proceed after this, or if this is even alright.

    The reason why I want to attach childs to a parent is because I can just make the parent's size escale with the scene's scaling-resizing and have the children react with their parent and it's own coordinates and proportions.

    Think of a graph in a window. If your window changes sizes, the graph rescales everything in accordance with the window's new parameters of height and width and, with that, so get the children to change.

  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: Handling Objects coordinates related to another object.

    Quote Originally Posted by alitoh View Post
    I want each child I create to use its parameters (ones that I pass to it when instantiated) and create itself taking as 0,0 the parent object's 0,0, not the scene's 0,0.
    That's exactly what happens by default if one item is parent to the other. If it doesn't work out of the box, you must have done something wrong.
    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. How to call objective-C objects from my C++ object (on OS X)
    By Markus in forum General Programming
    Replies: 1
    Last Post: 3rd March 2011, 08:06
  2. Check if a object is null and destroy objects
    By ruben.rodrigues in forum Newbie
    Replies: 3
    Last Post: 2nd July 2010, 10:25
  3. object handling issue
    By prolink007 in forum Qt Programming
    Replies: 1
    Last Post: 12th April 2010, 07:42
  4. Replies: 3
    Last Post: 9th January 2010, 15:47
  5. Coordinates Related
    By jsmith in forum Qt Programming
    Replies: 0
    Last Post: 18th August 2009, 15:37

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.