Important: Please read the Qt Code of Conduct -

[SOLVED] How to paint a QGraphicsItemGroup object?

  • Hi,
    Currently I am programming a basic dialog to visualize a QGraphicsItem object. Using the paint() method is working pretty well with the single items:

    QGraphicsItem *item;
    item->paint(painter, option, widget);

    My problem occurs when I try to visualize a QGraphicsItemGroup object, I don't get any error message but only an empty area, if I try this code:

    QGraphicsItemGroup *group;
    group->paint(painter, option, widget);

    So, I would like to know what is the right way to paint a group in this context? Thanks.

  • Finally, I found a nice way to visualize a QGraphicsItemGroup in an accurate way. Here is the code:

       if (QGraphicsItemGroup *group = qgraphicsitem_cast<QGraphicsItemGroup *>(item)) {
            foreach (QGraphicsItem *child, group->childItems())
                     child->paint(painter, option, widget);
        } else {
            item->paint(painter, option, widget);

    I hope this trick can be useful for somebody else ;)

Log in to reply