Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get coordinates of mouse click on the widget?
QtWS25 Last Chance

How to get coordinates of mouse click on the widget?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 18.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AFI4ever
    wrote on last edited by
    #1

    Hello,
    I have an object called "widget". It's class "cellularwidget" is a child of "QWidget". I need to get coordinates of mouse click in this widget when I click on it. How can I do that?

    Thank you!

    1 Reply Last reply
    0
    • K Offline
      K Offline
      Kxyu
      wrote on last edited by
      #2

      You should read a couple of tutorials or something. It's too easy and direct answers would spoil your experience.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AFI4ever
        wrote on last edited by
        #3

        I read help for class "QWidget" but I could not find any function for that.

        1 Reply Last reply
        0
        • EddyE Offline
          EddyE Offline
          Eddy
          wrote on last edited by
          #4

          Here is an "example":http://doc.qt.nokia.com/4.7/widgets-scribble.html using mousepressevent.

          Qt Certified Specialist
          www.edalsolutions.be

          1 Reply Last reply
          1
          • N Offline
            N Offline
            Nice
            wrote on last edited by
            #5

            Kxyu: I've also been looking at the documentation for mousePressEvent in the QWidget documentation, but it doesn't mention anything about mouse coorinates. Just saying that "it’s too easy" doesn't really help, it just declares the other person an idiot.

            Eddy: Thanks for the link, but it seems broken. Do you think you could update it or post a new one?

            Edit: Found the answer:

            @
            // Extract the coordinates from the QMouseEvent object
            int x = event->x();
            int y = event->y();
            @

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved