drawing points based on mouse clicks, how to create handle event for mouse clicks
hi, I have a small problem in knowing the position of a mouse on a QGraphicsViewScene. How can i know the x,y and handle clicks to draw points in their place and later create a shape filled with black color.
regards
Re: drawing points based on mouse clicks, how to create handle event for mouse clicks
1 Attachment(s)
Re: drawing points based on mouse clicks, how to create handle event for mouse clicks
thanks, i was alble to use mousePressEvent and was able to update the cooirdinates in a lable but i couldn't use QGraphicsSceneMouseEvent, i changed (QMouseEvent to QGraphicsSceneMouseEvent) but it didnt return anything. the problem is that the cooirdinates are relative to the main window not my GraphicsView. please see attached image for demonstration.
Attachment 4580
Code:
void MainWindow
::mousePressEvent(QMouseEvent *mouseEvent
)
{
ui->lblX->setText(x.toString());
ui->lblY->setText(y.toString());
}
Re: drawing points based on mouse clicks, how to create handle event for mouse clicks
for any one who reads this i did it using QEventFilter.
this topic was helpful: http://www.qtcentre.org/threads/6272...cking-on-image
this is the code i use:
in header file:
in .cpp
Code:
//filter mouse tracking to the selection area only
if(o!= lblScrollImage) return false;
if(e
->type
()==QEvent::MouseMove){ ui->lblX->setText(x.toString());
ui->lblY->setText(y.toString());
//polyPoints << QPoint(x.toInt(), y.toInt());
}
else if (e
->type
()==QEvent::MouseButtonPress) {
ui->lblX->setText(x.toString());
ui->lblY->setText(y.toString());
ui->lineEditX->setText(x.toString());
ui->lineEditY->setText(y.toString());
polyPoints <<
QPoint(x.
toInt(), y.
toInt());
}
return false;
}
regards,
ahmed