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. Change in the geometry of item on changing parent
Forum Updated to NodeBB v4.3 + New Features

Change in the geometry of item on changing parent

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 806 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.
  • D Offline
    D Offline
    djasmine
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0
      • D Offline
        D Offline
        djasmine
        wrote on last edited by
        #3

        /* 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
        0
        • D Offline
          D Offline
          djasmine
          wrote on last edited by
          #4

          Anybody having any expertise around this problem, please share.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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
            0

            • Login

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