Displaying coordinates of a pixel when moving mouse over Pixmap
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
Re: Displaying coordinates of a pixel when moving mouse over Pixmap
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.
Re: Displaying coordinates of a pixel when moving mouse over Pixmap
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
Re: Displaying coordinates of a pixel when moving mouse over Pixmap
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
Re: Displaying coordinates of a pixel when moving mouse over Pixmap
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
Re: Displaying coordinates of a pixel when moving mouse over Pixmap
So subclass the label and reimplement its paintEvent() as already said.
Re: Displaying coordinates of a pixel when moving mouse over Pixmap
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.