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. Get mouse cursor position in pixels

Get mouse cursor position in pixels

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 7.6k Views 3 Watching
  • 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.
  • V Offline
    V Offline
    Violet Giraffe
    wrote on last edited by
    #1

    I was just debugging a weird problem when I realized mouse coordinates are now returned in some abstract points, not physical pixels. Possibly due to changes in high DPI support (this is on Mac with retina display).
    I've got an OpenGL widget and I need coordinates in pixels in order for everything to work. As it is now, Qt seems to be dividing pixel coordinates by 2 (window height is 1600 and the cursor position only goes up to 800).

    How can I get the cursor position in pixels from mouse events?

    M 1 Reply Last reply
    0
    • V Violet Giraffe

      I was just debugging a weird problem when I realized mouse coordinates are now returned in some abstract points, not physical pixels. Possibly due to changes in high DPI support (this is on Mac with retina display).
      I've got an OpenGL widget and I need coordinates in pixels in order for everything to work. As it is now, Qt seems to be dividing pixel coordinates by 2 (window height is 1600 and the cursor position only goes up to 800).

      How can I get the cursor position in pixels from mouse events?

      M Offline
      M Offline
      mostefa
      wrote on last edited by
      #2

      @Violet-Giraffe said in Get mouse cursor position in pixels:

      I was just debugging a weird problem when I realized mouse coordinates are now returned in some abstract points, not physical pixels. Possibly due to changes in high DPI support (this is on Mac with retina display).
      I've got an OpenGL widget and I need coordinates in pixels in order for everything to work. As it is now, Qt seems to be dividing pixel coordinates by 2 (window height is 1600 and the cursor position only goes up to 800).

      How can I get the cursor position in pixels from mouse events?

      How are you getting the mouse pos

      Have you tried qcursor::pos ?

      http://doc.qt.io/qt-5/qcursor.html#pos-1

      V 1 Reply Last reply
      0
      • M mostefa

        @Violet-Giraffe said in Get mouse cursor position in pixels:

        I was just debugging a weird problem when I realized mouse coordinates are now returned in some abstract points, not physical pixels. Possibly due to changes in high DPI support (this is on Mac with retina display).
        I've got an OpenGL widget and I need coordinates in pixels in order for everything to work. As it is now, Qt seems to be dividing pixel coordinates by 2 (window height is 1600 and the cursor position only goes up to 800).

        How can I get the cursor position in pixels from mouse events?

        How are you getting the mouse pos

        Have you tried qcursor::pos ?

        http://doc.qt.io/qt-5/qcursor.html#pos-1

        V Offline
        V Offline
        Violet Giraffe
        wrote on last edited by
        #3

        @mostefa said in Get mouse cursor position in pixels:

        How are you getting the mouse pos

        mouseEvent->pos(). QCursor::pos() is not a substitute for that, for obvious reasons.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          Violet Giraffe
          wrote on last edited by Violet Giraffe
          #4

          Bump. This is a very serious issue. There must be some way to convert the mouse coordinates into system units!

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            What about QScreen::devicePixelRatio ?

            By the way, what version of Qt are you using ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            V 1 Reply Last reply
            2
            • SGaistS SGaist

              Hi,

              What about QScreen::devicePixelRatio ?

              By the way, what version of Qt are you using ?

              V Offline
              V Offline
              Violet Giraffe
              wrote on last edited by Violet Giraffe
              #6

              @SGaist said in Get mouse cursor position in pixels:

              By the way, what version of Qt are you using ?

              Hi, thank you, on-point answer as always. That works, but it raises a question: if there are multiple monitors, how do I know which QScreen to use?
              P. S. Think I've found a way: QApplication::desktop()->screenNumber(widget) obtains the screen number which can be used to get the screen from QApplication::screens().

              I'm using Qt 5.8 on Mac.

              1 Reply Last reply
              0

              • Login

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