Flipping all the Items in a Graphics View
-
I want to flip all the items within a graphicsview. I don't want to flip the view because I don't want to flip the coordinate system of the view. I want point(0,0) to remain in the top left corner of the sceneRect. The following codes almost does what I want. However it expands out the sceneRect by around 10 %. Any suggestion? Any more simple or elegant solutions?
void MainWindow::flipHorizontal()
{
QList<QGraphicsItem*> allItems = scene->items();QTransform xForm; xForm.scale(-1,1); xForm.translate(-( scene->sceneRect().width() ), 0); foreach(QGraphicsItem* item, allItems) { item->setTransform(xForm); }
}
-
I've seemed to have solved the problem with the scene expanding......the below seems to work quite good. But is there another way to do this that is more simple and elegant?
void MainWindow::flipHorizontal()
{
QList<QGraphicsItem*> allItems = scene->items();QTransform xForm; xForm.scale(-1,1); xForm.translate(-( scene->sceneRect().width() ), 0); foreach(QGraphicsItem* item, allItems) { item->setTransform(xForm); } scene->setSceneRect(scene->itemsBoundingRect());
}