當我嘗試旋轉一個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