PDA

View Full Version : QGraphicsItem Parent/Child vs. QGraphicsItemGroup



volQt
17th October 2011, 22:55
Hi fellas,

I've been trying to wrap my head around Qt' QGraphicsView/Scene/Item framework.
I have been experimenting with complex custom QGraphicsItems. There is one thing
I apparently seem to understand in a wrong way. So here's the question:
What exactly makes an QGraphicsItemGroup with items A,B,C different to
a QGraphicsItem A which is passed as parent to QGraphicsItem B which is passed as parent to QGraphicsItem C (except the difference in coordinate system interpretation)?

I was under the assumption that in case of a parent child relationship the child would be moved together with
the parent if QGraphicsItem::ItemIsMovable is set for the parent. However, when I implement this
I can only move the parent around. Since, I am quite new to Qt in general I might be missing something.
If anyone could point me as to whether my assumption is wrong or not it would be a great help.

Thanx and Cheers,
volQt

volQt
18th October 2011, 06:29
Sorry, found the answer in a different thread.
So apparently I've relied on the parent argument of the constructor to set the parent/child relationship, which didnt work.
I had also tried setParent(someItem), which didnt work either but did compile because some class in the inheritance hierarchy provided this function.
The trick is hence to use

childItem->setParentItem(someItem);


Cheers, volQt.