PDA

View Full Version : QGraphicsView, QGraphicsScene item coordinates in scene



harakiri
29th September 2010, 08:40
Hi,

i have some trouble retrieving an item's position in scene coordinates.
currently the code looks like:



void view::mousePressEvent(QMouseEvent* event)
{
if (event->button()==Qt::LeftButton)
{
Vertex::Vertex* vertex = new Vertex::Vertex(QRect(event->x(), event->y(), 2, 2));
vertex->setZValue(3);
m_scene->addItem(vertex); // QGraphicsScene*
std::cout << "Pos: " << vertex->pos().x() << " : " << vertex->pos().y() << std::endl;
}
}


but pos() always returns 0:0. i have read the documentation (http://doc.trolltech.com/4.3/qgraphicsscene.html) and tried a lot of things (setPos,mapToScene, scenePos..) but always retrieve a wrong or zero position.

which function do i have to call to retreive the coordinates set by event->x(), event->y() ?

thanks in advance

harakiri
5th October 2010, 10:23
can someone help me?

tejainece
5th December 2010, 10:02
use mouseEvent->scenePos().rx() and mouseEvent->scenePos().ry() instead of mouseEvent->pos()