PDA

View Full Version : Retrieving mouseover coordinates of QGraphicsScene



forrestfsu
23rd October 2006, 14:34
I have a QGraphicsView with a set QGraphicsScene. I'm trying to get the coordinates (on mouseover) of where the mouse is relative to the scene. I'm able to get the coordinates of the entire screen, but not the scene. Is there any way to accomplish this?

This is the code I have so far, but it only returns the window coordinates:


bool Form::eventFilter(QObject *o, QEvent *e)
{
if (o = ui.graphicsView->viewport()){
QPoint a = QCursor::pos();
QString coord = QString::number(a.x()) + ", " + QString::number(a.y());
ui.coordLabel->setText(coord);
}
}

jacek
23rd October 2006, 16:13
You will need QWidget::mapFromGlobal() and QGraphicsView::mapToScene().

forrestfsu
23rd October 2006, 18:36
Thanks for the tip! this is what I did incase anyone ever needs it:



QPointF a = ui.graphicsView->mapToScene(ui.graphicsView->mapFromGlobal(QCursor::pos()));