Results 1 to 7 of 7

Thread: Displaying coordinates of a pixel when moving mouse over Pixmap

  1. #1
    Join Date
    Oct 2008
    Posts
    74
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.

  3. #3
    Join Date
    Oct 2008
    Posts
    74
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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

  5. #5
    Join Date
    Oct 2008
    Posts
    74
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Displaying coordinates of a pixel when moving mouse over Pixmap

    So subclass the label and reimplement its paintEvent() as already said.

  7. #7
    Join Date
    Mar 2018
    Posts
    1
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Windows

    Default 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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.