PDA

View Full Version : Rotating QGraphicsEllipseItem, but keeping its location



forrestfsu
24th October 2006, 19:32
I have a QGraphicsEllipseItem which I would like to rotate, but place on a certain location of the scene. I can get it to rotate, but it seems to automatically place the ellipse somewhere else on the scene. This is a snippit of the code I have so far, any help would be appreciated.



ellipse = new QGraphicsEllipseItem(x-1, y-7, 2, 7);
ellipse->rotate(45.0);
// Tried the following with no success:
// ellipse->setPos(x,y);
// ellipse->setPos(ui.graphicsView->mapFromScene(x,y));
// ellipse->setPos(ui.graphicsView->mapToScene(x,y));
scene->addItem(ellipse);

jacek
24th October 2006, 23:00
Could you post a screenshot, so we can see what's wrong?

Hannu Männistö
9th February 2012, 13:47
This is how i made it.


foreach(QGraphicsItem *item, graphicScene->selectedItems()){
QString val = item->data(1).toString(); // This check is merely because I have 1 parent QGraphicsItem which is not intended to rotate
if(val.isEmpty()){
QRectF br= item->boundingRect();
item->setTransformOriginPoint(br.center());
item->setRotation(item ->rotation() + 10.0);
item->update();
graphicScene->update();
}
}