I have an object on the scene - a card with two sides and text elements on it.

The map is in horizontal orientation (it is landscape). It was necessary to turn the map into a vertical orientation, so that some of the elements remained in place and turned around with the map, while the other part moved relative to the new upper left corner. The screenshots will be clearer.

Current situation: enter image description here

I want to be so: enter image description here

Minimum project with a problem: https://github.com/gil9red/card_design_test

    2 answers 2

    It seems to me that if you make a layout on the card object and put your own TextElement elements on it, they will rotate with the map when you create .rotate (-90). Or make cadr parent_ for TextElement_s. It should work together. I did not check it myself ...

    • So it is so, but you need to be able to change the flag of the element, after which it either turns with the map, or takes a new position (as on the second screen). This is where I fail. - gil9red

    In order for the elements on the flag to be rotated with the map (let's call them fixed) or to be placed on it, taking into account the location on the new upper corner of the map, it was necessary to do:

    • All items are located on the stage.
    • Place all items manually.
    • For fixed elements, rotation is performed manually

    The map turned like this:

    // Поворот всей карты QPointF center = card->boundingRect().center(); QTransform transform; if (checked) { transform.translate(center.x(), center.y()) .rotate(-90) .translate(-center.x(), -center.y()); } else { transform.translate(center.x(), center.y()) .rotate(90) .translate(-center.x(), -center.y()); } card->setTransform(transform, true); card->isLandscape = !checked; needRotate = true; on_actionFill_triggered(); 

    The placement of elements on the map is done manually, taking into account which side of the map the element is on and whether it is fixed:

     for (TextElement* item: items) { QPointF pos(item->_x, item->_y); CardSide* side = item->isFrontSide ? card->frontSide : card->backSide; if (!item->isFixedPos) { // Альбомная ориентация if (card->isLandscape) { pos = side->pos() + pos; // Портретная ориентация } else { QPointF posSide = card->mapToScene(side->pos() + side->boundingRect().topRight()); pos = posSide + pos; } } else { // Поворот зафиксированного элемента QTransform transform; // временный костыль if (needRotate) if (!card->isLandscape) { transform.rotate(-90); } else { transform.rotate(90); } item->setTransform(transform, true); if (card->isLandscape) { pos = side->pos() + pos; } else { QPointF posSide = card->mapToScene(side->pos()); pos = QPointF(posSide.x() + pos.y(), posSide.y() - pos.x()); } } item->setPos(pos); } 

    Test project .

    Screenshot:

    enter image description here