I am displaying multiple QGraphicsPolygonItem's inside a QGraphicsView. When I hover the mouse inside one of the QGraphicsPolygonItem, I need the pixel position under the mouse relative to the Upper Left Hand Corner of the QGraphicsPolygonItem. I have overloaded the mouseMoveEvent of QGraphicsPolygonItem, and am trying to get the values on mousemove (Code below).
QRectF myBoundingRectangle
= this
->sceneBoundingRect
();
QPointF currMousePointF
= this
->mapToScene
(currMousePoint
);
QPointF currEventPoint
= event
->pos
();
int xRelative = currMousePointF.x() - myBoundingRectangle.topLeft().x();
int yRelative = currMousePointF.y() - myBoundingRectangle.topLeft().y();
MovableRectangle::mouseMoveEvent(event);
}
void MovablePolygonItemWithHistogram::mouseMoveEvent( QGraphicsSceneMouseEvent * event ){
QRectF myBoundingRectangle = this->sceneBoundingRect();
QPoint currPos = this->pos();
QPoint currMousePoint = QCursor::pos();
QPointF currMousePointF = this->mapToScene(currMousePoint);
QPointF currEventPoint = event->pos();
int xRelative = currMousePointF.x() - myBoundingRectangle.topLeft().x();
int yRelative = currMousePointF.y() - myBoundingRectangle.topLeft().y();
MovableRectangle::mouseMoveEvent(event);
}
To copy to clipboard, switch view to plain text mode
QCursor::pos() gives me the correct mouse coordinates WRT the computer screen. However, myBoundingRectangle always returns the position where I placed it on the parent QGraphicsView. If I try to find location of the QGraphicsPolygonItem using pos() or scenePos() (currPos), it is always 0, 0.
What should I be doing to get xRelative and yRelative? I read through "The Graphics View Coordinate System" at http://developer.qt.nokia.com/doc/qt...rdinate-system, and am possibly missing something simple here. Would appreciate any pointers.
Bookmarks