Important: Please read the Qt Code of Conduct -

QGraphicsSvgItem appears two times after adding to scene and moving it

  • Hello everyone,
    It seems like a simple thing, but I could not find a solution to the following problem. Maybe I am missing somthing obvious, but it would be great, if you could point out what else I can check to solve this.

    Problem description:
    I do have a scene, which contains a QGraphicsSvgItem as a child of a custom made QGraphicsObject.
    After adding, the position of the new child is off, so I use moveBy(…) to correct that and recalculate the parents boundingRect to include the child as well.

    But after doing so, I do have the child drawn twofold in the scene: Once at the position it was initially added and once in the position it was moved to. I tried updating and redrawing the whole scene, but nothing seems to change.

    The function that seems responsible for the issue. I abbreviated some irrelevant things, to focus on the main problem. You can however find the full code at github.

     ModulePortGI::ModulePortGI(…) : PortGraphicsItem(…) {
     int moveX;
     int moveY;
     QGraphicsSvgItem* decal;
     switch(direction) {
    case model::enums::PortDirection::OUT :
        decal = new QGraphicsSvgItem(":/…/outside_port_out.svg", this);
        moveX = 0;
        moveY = -decal->boundingRect().height()/2;
    case model::enums::PortDirection::IN :
        decal = new QGraphicsSvgItem(":/…/outside_port_in.svg", this);
        moveX = -decal->boundingRect().width();
        moveY = -decal->boundingRect().height()/2;
    default : // should not happen
    Q_ASSERT(decal->parentItem() == this);
    decal->moveBy(moveX, moveY);

    The function addActual(…) is defined in a base class SchematicElement as

    SchematicElement::addActual(QGraphicsItem* actual) {

    This also is the case for recalculateBoundingRect(). (Which I found to be working as expected, so I leave that out.)

    So, what else could I check to get this sorted out?
    Thanks in advance.