Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Is this a bug or undocumented feature in 'void QGraphicsItemGroup::addToGroup(QGraphicsItem *item)' ?



  • The documentation clearly states that the function reparents the passed item to the group, but it also seems to set the 'QGraphicsItemGroup * QGraphicsItem::group () const' -pointer of all of that item's own children to this same group (not touching parentItem() -pointer of course)! This behavior is not documented and it messes up the easy distinction whether a specific item belongs to a group or is a child of another item that belongs to a group.

    This could be a bug or just documentation shortage. I'm currently seeing this in Qt 4.7.3.



  • This sounds like a shortcoming of the documentation. I have asked our documentation team to add this information to the documentation, see:

    http://bugreports.qt.nokia.com/browse/QTBUG-19808



  • Thank you.

    If this behavior is not wanted (as in my case) you can circumvent it by removing and reparenting the children. Example below

    @
    QList<QGraphicsItem *> childItemList = itemToBeAdded->childItems();
    foreach (QGraphicsItem *child, childItemList)
    child->setParent(0);

    someGroup->addToGroup(itemToBeAdded);

    foreach (QGraphicsItem *child, childItemList)
    child->setParent(itemToBeAdded);
    @


Log in to reply