Results 1 to 2 of 2

Thread: getting mouse coordinates

  1. #1
    Join Date
    Nov 2007
    Posts
    57
    Thanks
    36
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default getting mouse coordinates

    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.

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

    Default Re: getting mouse coordinates

    Reimplement mousePressEvent() for your widget. It will be called whenever mouse button is pressed. The position of the click is carried within the parameter.

Similar Threads

  1. Weird behaviour of mouse events and QMenu pop-ups
    By Ishark in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 08:46
  2. Move Rectangle on mouse Move
    By vermarajeev in forum Qt Programming
    Replies: 24
    Last Post: 14th May 2007, 06:34
  3. mouse moving don't produce mouse events
    By coralbird in forum Qt Programming
    Replies: 1
    Last Post: 13th September 2006, 07:13
  4. Replies: 2
    Last Post: 24th July 2006, 19:36
  5. QStackerWidget and mouse events
    By high_flyer in forum Qt Programming
    Replies: 3
    Last Post: 25th April 2006, 20:25

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.