Results 1 to 4 of 4

Thread: Please help with child object coordinates

  1. #1
    Join Date
    Sep 2011
    Posts
    19
    Qt products
    Qt4
    Platforms
    Windows

    Default Please help with child object coordinates

    I'm placing the symbols in a musical key signature on a musical staff. This part is successful. All the symbols are successfully placed individually using scene->addItem(mySigItem); mySigItem->setPos(tx,ty);

    But I'd like the first symbol to be the parent item and the rest of the symbols be child items so that the key signature can be moved as a single piece. When I change the lines to mySigItem2->setParentItem(mySigItem1) then the position of the second item is FAR to the right and down the screen. I have tried setting the flag ItemIgnoresTransformations, mapTo/FromScene, mapFrom/ToParent, etc. and everything else I can think of or find in the docs. The coordinates work individually placed but simply setting the item as a child breaks them and they wander off.

    Please help me figure out what I'm doing wrong. Thanks.

  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: Please help with child object coordinates

    Item position is always determined relative to its parent (or the scene if the item has no parent). Thus you need to set position of notes relative to the key item. If you only know the absolute scene position then you can always use keyItem->mapFromScene() to determine the position relative to the key item.
    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. #3
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Please help with child object coordinates

    Quote Originally Posted by devdon View Post
    . . .so that the key signature can be moved as a single piece.
    Take a look at QGraphicsItemGroup

  4. #4
    Join Date
    Sep 2011
    Posts
    19
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Please help with child object coordinates

    thanks for your response.

    QGraphicsItemGroup is just what I was looking for but had overlooked in the docs. Thanks!

    This relative behavior is counter-intuitive to my newbie brain. I think in scene coordinates. But I see now how I can work it out. Thank you very much for your response.
    Last edited by devdon; 5th October 2011 at 20:54. Reason: error

Similar Threads

  1. browse through all the child object of a widget
    By qlands in forum Qt Programming
    Replies: 2
    Last Post: 6th July 2011, 08:23
  2. How to save Child if Parent Object is deleted.
    By vaibhav in forum Qt Programming
    Replies: 6
    Last Post: 25th May 2011, 08:52
  3. Replies: 1
    Last Post: 31st March 2011, 10:41
  4. Child object not showing
    By BalaQT in forum Qt Programming
    Replies: 2
    Last Post: 24th September 2009, 14:46
  5. Replies: 9
    Last Post: 9th May 2006, 19:53

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.