Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGraphicsSvgItem appears two times after adding to scene and moving it

QGraphicsSvgItem appears two times after adding to scene and moving it

Scheduled Pinned Locked Moved General and Desktop
qgraphicssceneqgraphicssvgiteqgraphicsitem
1 Posts 1 Posters 865 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fer-rum
    wrote on last edited by
    #1

    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.

    Code:
    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;
        break;
    case model::enums::PortDirection::IN :
        decal = new QGraphicsSvgItem(":/…/outside_port_in.svg", this);
        moveX = -decal->boundingRect().width();
        moveY = -decal->boundingRect().height()/2;
        break;
    default : // should not happen
        Q_ASSERT(false);
    }
    this->addActual(decal);
    Q_ASSERT(decal->parentItem() == this);
    decal->moveBy(moveX, moveY);
    this->recalculateBoundingRect();
    }
    

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

    void
    SchematicElement::addActual(QGraphicsItem* actual) {
        m_actuals.append(actual);
        actual->setParentItem(this);
        this->recalculateBoundingRect();
    }
    

    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.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved