PDA

View Full Version : How to get the exact location from a click on the qgraphicsscene



ivory
12th March 2014, 02:59
Hi, I am writing codes to load in image from a file and did some edits on this image(change some pixels' value), zoomed in or zoomed out and then save the image.
Also, I want to know the location in the original image associated to a click on the qgraphicsscen. Up till now, I can not find any function useful.

My codes for loading image:
qgraphicsscene = myqgraphicsview->getScene();
qgraphicsscene->setSceneRect(image->rect());
myqgraphicsview->setScene(qgraphicsscene);
qgraphicsscene->addPixmap(QPixmap::fromImage(*image));

My codes for editing:
mousePressEvent(QMouseEvent * e){
QPointF pt = mapToScene(e->pos());
scene->addEllipse(pt.x()-1, pt.y()-1, 2.0, 2.0,
QPen(), QBrush(Qt::SolidPattern));}
I want to know the relationship between e->pos() and the exact location in the original image.

anda_skoa
12th March 2014, 09:28
Lets see: you have the point in scene coordinates. QGraphicsItem has a method called mapFromScene().

I wonder if that could be used to map the point to item coordinates of the pixmap item. What do you think?

Cheers,
_