PDA

View Full Version : Parent QGraphicsItem and QGraphicsItemGroup



jano_alex_es
28th July 2009, 13:53
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?

yogeshgokul
28th July 2009, 14:10
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.

jano_alex_es
28th July 2009, 14:45
the problem is here:



QHash<int, CLineElemItem*>::const_iterator iter = m_hashElemItems.constBegin();

while(iter != m_hashElemItems.constEnd())
{
iter.value()->setParent(this);

int numberOfChildItems = childItems().size();
}



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

wysota
28th July 2009, 14:58
There is no such thing for graphics items as "setParent". There is QGraphicsItem::setParentItem().

jano_alex_es
29th July 2009, 09:15
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!

wysota
29th July 2009, 09:17
Your CLineElemItem probably inherits QObject which has a QObject::setParent() method.