I want to track mouse in my main window. I have enabled the moustracking in the QGraphicsView here is the constructor for GraphicsView subclass, the rest is the default behavior.
GraphicsView::GraphicsView(QWidget* parent): QGraphicsView(parent)
{
setMouseTracking(true);
setDragMode(RubberBandDrag);
setRenderHints(QPainter::Antialiasing| QPainter::TextAntialiasing);
setMinimumSize(600, 400);
}
here is my GraphicsScene MouseMove method:
void GraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
if (myMode == InsertLine && line != nullptr) {
QLineF newLine(line->line().p1(), mouseEvent->scenePos());
line->setLine(newLine);
} else if (myMode == Select) {
QGraphicsScene::mouseMoveEvent(mouseEvent);
}
QPointF point = mouseEvent->pos();
//point = this->mapToScene(point);
qDebug() << point.x() << " " << point.y() << " ";
mouseMoved(point);
QGraphicsScene::mouseMoveEvent(mouseEvent);
}
I get zero and zero for x and y position. What am i doing wrong ?