Hi,
i have some trouble retrieving an item's position in scene coordinates.
currently the code looks like:
{
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;
}
}
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;
}
}
To copy to clipboard, switch view to plain text mode
but pos() always returns 0:0. i have read the documentation 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
Bookmarks