Results 1 to 6 of 6

Thread: Parent QGraphicsItem and QGraphicsItemGroup

  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 Parent QGraphicsItem and QGraphicsItemGroup

    Hi,

    I have some items I'd like to have "inside" other one; when I move the parent I want to move the childs as well.

    I was trying with QGraphicsItemsGroup, but I am having problems when I move it. So it's not an option.

    When I set some items as childs of other, if I move the parent the childs are not supposed to move, isn't? so, what exactly this parent-child system does?

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Parent QGraphicsItem and QGraphicsItemGroup

    Quote Originally Posted by jano_alex_es View Post
    When I set some items as childs of other, if I move the parent the childs are not supposed to move, isn't?
    Yes, this is the intended behavior. Ideally what you are doing should work. Can you please paste some code, where you are creating items and setting their parent.

  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

    Exclamation Re: Parent QGraphicsItem and QGraphicsItemGroup

    the problem is here:

    Qt Code:
    1. QHash<int, CLineElemItem*>::const_iterator iter = m_hashElemItems.constBegin();
    2.  
    3. while(iter != m_hashElemItems.constEnd())
    4. {
    5. iter.value()->setParent(this);
    6.  
    7. int numberOfChildItems = childItems().size();
    8. }
    To copy to clipboard, switch view to plain text mode 


    this code is inside the parent object. But numberOfChildItems is always zero... I'm missing something, and I bet It's something stupid :P

  4. #4
    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: Parent QGraphicsItem and QGraphicsItemGroup

    There is no such thing for graphics items as "setParent". There is QGraphicsItem::setParentItem().
    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.


  5. #5
    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: Parent QGraphicsItem and QGraphicsItemGroup

    yep, that was one of the problems.

    By the way, I don't understand why the compiler didn't display an error :S

    well, finally solved. Thanks!

  6. #6
    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: Parent QGraphicsItem and QGraphicsItemGroup

    Your CLineElemItem probably inherits QObject which has a QObject::setParent() method.
    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.


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.