0

I encountered a strange issue/feature when I try to rotate a QGraphicsSvgItem object and set a position.

Check the following example: I have one .svg for the sake of simplicity that is a blue rectangle. I create two QGraphicsSvgItem using the file and I rotate on of them with 90 degree. I set both of them to the same position, however the rotated one positioned 'wrongly'(maybe that is the correct behaviour). It looks like that the x,y coordinate(top-left corner) is now the top-right corner, remains like that it is not rotated. It looks strange from my viewpoint, I expect that when I rotate and set the position the 'first point' of the shape should be where the shape 'starts'.

I hope with the source code is more understandable that I wrote above:

    SVGDom *bubbleDom = shadowgram->bubble();
    _bubble = new DrawableSvgItem(sh->message(), bubbleDom->byteArray());
    this->addItem(_bubble);
    _bubble->setPos((this->width()-_bubble->sceneBoundingRect().width()) / 2, (this->height() - _bubble->sceneBoundingRect().height()) / 2);
    qDebug() <<"Bubble pos: " << _bubble->pos();
    qDebug() <<"Bubble boundindRect: " << _bubble->boundingRect();
    qDebug() << "Bubble rect: " <<_bubble->sceneBoundingRect();
    qDebug() << "Bubble topleft: " <<_bubble->sceneBoundingRect().topLeft();

    DrawableSvgItem *bubble2 = new DrawableSvgItem(sh->message(), bubbleDom->byteArray());
    this->addItem(bubble2);
    bubble2->setRotation(90);
    bubble2->setPos(_bubble->pos());
    qDebug() << "Bubble2 pos: " << bubble2->pos();
    qDebug() <<"Bubble2 boundindRect: " << bubble2->boundingRect();
    qDebug() << "Bubble2 rect: " <<bubble2->sceneBoundingRect();
    qDebug() <<"Bubble2 topleft: " << bubble2->sceneBoundingRect().topLeft();

DrawableSvgItem is only an extension of QGraphicsSvgItem, I created for drawing sourcepaths into the item. Currently I am not using it.

Output:

Bubble pos:  QPointF(413.5, 297)
Bubble boundindRect:  QRectF(0,0 171x117)
Bubble rect:  QRectF(296.5,297 117x171)
Bubble topleft:  QPointF(296.5, 297)
Bubble2 pos:  QPointF(413.5, 297)
Bubble2 boundindRect:  QRectF(0,0 171x117)
Bubble2 rect:  QRectF(411.458,297 173.016x119.967)
Bubble2 topleft:  QPointF(411.458, 297)

In pictures, I expect the following:

enter image description here

But I got the following image:

enter image description here

I found a similar problem here.

4

1 に答える 1