PDA

View Full Version : getting mouse coordinates



eric
14th November 2007, 20:23
Hi all. I have a QPixmap image that I display using QLabel. I'd like to obtain mouse coordinates as I click on the image. What is the easiest way to do that?

I read about QMouseEvents class and it seems that I need to use: "QWidget::setEnabled()" and then use "const QPoint & pos () const" to get the coordinates. I don't know how to implement this.

Does anyone know of a simple example where they obtain coordinates (relative to a widget) with mouse? Eventually I need to be able to click on my widget (and hold down they button), then drag mouse and as I release mouse button the two coordinates (at the time of clicking and at the time of releasing mouse) are reported.

wysota
14th November 2007, 20:34
Reimplement mousePressEvent() for your widget. It will be called whenever mouse button is pressed. The position of the click is carried within the parameter.