PDA

View Full Version : QGraphicsItem scale around arbitrary origin - problem with scenePos



MadBear
10th December 2010, 11:10
Greetings,
I have tried to scale QGraphicsItem (QGraphicsPixmapItem) around center point of pixmap (with setTransform(QTransform().translate(x, y).scale(sx,sy).translate(-x, -y)) like in documentation). Now if I try to save scenePos and then reproduce it the final position of that item is different than saved position. What am I missing?

Regards,
MadBear

MadBear
15th December 2010, 11:24
Greetings,
To further explain what is the problem:

1. Creation of item


QGraphicsPixmap *pix=new QGraphicsPixmap();
pix->setPixmap(somePixmap);
scene->addItem(pix);


2. Mouse wheel event on scene


resetTransform();
QRectF brc=boundingRect();
setTransform(QTransform::fromTranslate(-brc.width()/2.0, -brc.height()/2.0)*QTransform::fromScale(sx, sy).rotate(alpha)*QTransform::fromTranslate(brc.wi dth()/2.0, brc.height()/2.0), true);


3. Do something with scene position of item


QList<QGraphicsItem*> sel=selectedItems();
int i;
for(i=0;i<sel.count();i++)
{
QPointF xy=sel[i]->scenePos();
sel[i]->setPos(xy.x(),xy.y()-tranStep); //here the position should only change for tranStep but it does not (the change is much larger and rotation also affects change in position)
}


I hope this further explains what am I trying to achieve and where is the problem.
Thank you.

Regards,
MadBear