Results 1 to 7 of 7

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    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.

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

    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

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

    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

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

    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

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    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.

  6. #6
    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
  •  
Qt is a trademark of The Qt Company.