Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Change in the geometry of item on changing parent

    General and Desktop
    2
    5
    412
    Loading More Posts
    • 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.
    • D
      djasmine last edited by

      Say I have an item A which is child of a parent P1.
      Now I rotate item A by 180.
      I have another item P2 which is rotated by 90 and horizontally mirrored.
      Now when I try to make P2 as parent of item A, it's position, rotation and mirroring gets completely modified.

      I am able to fix the position of item by adjusting it based on its scene position.
      But I am unable to get its original transformations (rotate/mirror) back.
      How can I resolve this??
      Also is there any way to modify the scene transformation of any item ??

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        Can you share the related code ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • D
          djasmine last edited by

          /* Below I am sharing a minimal stand alone code simulating the problem shared above, its not the actual code from my project */

          QGraphicsView graphicsView;
          QGraphicsScene *scene = new QGraphicsScene(&graphicsView);
          graphicsView.setScene(scene);

          QGraphicsRectItem * parent1 = new QGraphicsRectItem();
          parent1 ->setRect(QRectF(-100, -50, 200, 100);
          parent1->setPos(100, 100);
          scene->addItem(parent1 );

          QGraphicsRectItem * parent2 = new QGraphicsRectItem();
          parent2 ->setRect(QRectF(-100, -50, 200, 100);
          parent2->setPos(250, 250);
          scene->addItem(parent2 );

          //parent1 being set as parent of text
          QGraphicsSimpleTextItem * text = new QGraphicsSimpleTextItem();
          text->setText("I am Text");
          text->setParentItem(parent1);
          text->setPos(QPointF(0,0));

          //rotate parent2 by 90 and then make it as parent of text
          QTransform tr;
          tr.rotate(90);
          parent2->setTransform(tr);
          text->setParentItem(parent2);

          Now text will jump to another position along with some rotation applied (inherited from parent).
          I am to handle to jump in position as below:

          QPointF oldPos = text->mapToScene(pos()); //fetch scene pos before setting parent2
          QPointF newPos = text->maptoScene(pos()); // fetch pos after setting parent2

          text->setPos( pos() + (oldPos - newPos) );

          Now text stays where it was created but rotates.
          How to stop rotation?
          I know there is a flag itemIgnoresTransformation.
          In our case there is a hierarchy of parents and some view transformations like zoom which we want to get automatically passed on to all the child items.
          So itemIgnoresTransformation is not the solution.

          1 Reply Last reply Reply Quote 0
          • D
            djasmine last edited by

            Anybody having any expertise around this problem, please share.

            1 Reply Last reply Reply Quote 0
            • SGaist
              SGaist Lifetime Qt Champion last edited by

              From the looks of it, you would have to implement your own filtering of the transformations applied to your scene but since it's all handled on a lower level.

              See the QGraphicsSceneBspTreeIndex.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply Reply Quote 0
              • First post
                Last post