Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    How to get coordinates of mouse click on the widget?

    General and Desktop
    4
    5
    17443
    Loading More Posts
    • 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
      AFI4ever last edited by

      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 Reply Quote 0
      • K
        Kxyu last edited by

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

        1 Reply Last reply Reply Quote 0
        • A
          AFI4ever last edited by

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

          1 Reply Last reply Reply Quote 0
          • E
            Eddy last edited by

            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 Reply Quote 1
            • N
              Nice last edited by

              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 Reply Quote 1
              • First post
                Last post