当我尝试旋转一个QGraphicsSvgItem
对象并设置一个位置时,我遇到了一个奇怪的问题/功能。QGraphicsSvgItem旋转后定位
检查以下示例: 为了简单起见,我有一个.svg
,它是一个蓝色的矩形。我创建了两个使用该文件的QGraphicsSvgItem
,并旋转90度。我将它们都设置在相同的位置,但旋转的一个位置“错误”(也许这是正确的行为)。它看起来像x,y坐标(左上角)现在是右上角,仍然像它没有旋转。从我的观点来看,这看起来很奇怪,我期望当我旋转并设置位置时,形状的“第一点”应该是形状“开始”的位置。
我希望能与源代码更容易理解我上面写道:
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只是QGraphicsSvgItem将的延伸,我绘制sourcepaths到项目创建。目前我没有使用它。
输出:
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)
在照片,我希望以下内容:
但我得到了下面的图片:
我发现了一个类似的问题here。
感谢您的回答和您的时间。我会尝试玩这个。 – flatronka 2014-10-28 10:48:27
这并不能真正解决我的问题。我尝试过,但几乎发生同样的事情。 – flatronka 2014-11-04 17:34:29
请参阅我的答案中的编辑 – 2014-11-05 11:31:31