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?
Re: Parent QGraphicsItem and QGraphicsItemGroup
Quote:
Originally Posted by
jano_alex_es
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.
Re: Parent QGraphicsItem and QGraphicsItemGroup
the problem is here:
Code:
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
Re: Parent QGraphicsItem and QGraphicsItemGroup
There is no such thing for graphics items as "setParent". There is QGraphicsItem::setParentItem().
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!
Re: Parent QGraphicsItem and QGraphicsItemGroup
Your CLineElemItem probably inherits QObject which has a QObject::setParent() method.