PDA

View Full Version : Displaying coordinates of a pixel when moving mouse over Pixmap



dbrmik
5th February 2009, 23:28
Hi

I have a pixmap displayed on a label. I would like to dynamically show the pixel position (x,y) as I move the mouse over the image (without mouse clicks). I think I need to use enable mouse tracking with mouseMoveEvent to get the current mouse position. But how do I display this on the pixmap at the cursor position

Regards

wysota
5th February 2009, 23:48
Yes, you need to enable mouse tracking. Furthermore you need to reimplement paintEvent() for the label, call the base class implementation and in addition to that do your painting. If I were you I wouldn't do that - I would instead use tooltips.

dbrmik
6th February 2009, 09:45
Hi

The label displaying the pixmap is the central widget in a mainwindow. Do I need to create my own qlabel , enable mousetracking and reimplement the event handler to catch the tooltip event?

Thanks

aamer4yu
6th February 2009, 11:12
I guess you have 2 options to proceed with -
1) show position as tool tip
This simply requires you to set mouse position as tool tip in mouseMoveEvent of QLabel.
But this will limit as tooltip display takes some time to popup.

2) Display position in status bar of QMainWindow.
You can capture mouse move events in main window, translate them to label cordinates and show in status bar

dbrmik
6th February 2009, 11:33
Thanks

So if I want to display pixel position attached to the cursor as the mouse moves over the image, the tooltip is not the solution as it is too slow updating the cursor position.

The second option would only display the cursor position in the status bar, I would like the position attched to the mouse cursor as it is moved over the image

Thanks

wysota
6th February 2009, 11:40
So subclass the label and reimplement its paintEvent() as already said.

radhikar
2nd March 2018, 04:39
Hi,
I have just started working with Qt. I want to extract the pixel coordinates on mouse click and this thread seemed relevant. Can I get a snippet of your code to understand how to implement it?
Thanks.