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. QCursor::pos() is not screen coordinates

QCursor::pos() is not screen coordinates

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.1k Views 2 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.
  • N Offline
    N Offline
    normvcr
    wrote on last edited by normvcr
    #1

    Recently switched to Fedora 32 x86-64 with QT5.13.2, and, now, QCursor::pos() is not returning screen coordinates. Instead, it has the following behaviour:

    1. When inside a QT application window of the application that calls QCursor::pos(), the returned coordinates are relative to the application window.
    2. When outside a QT application window, the returned coordinates are constant -- whatever was last returned when it was inside a QT application window.

    The doc says, The position is queried from the windowing system, so I suppose I need to set some flag somewhere??

    My distro does not supply a debuginfo version of the qt5 libraries, but I did check the source code for QCursor::pos():

    QPoint QCursor::pos(const QScreen *screen)
    {
        if (screen) {
            if (const QPlatformCursor *cursor = screen->handle()->cursor()) {
                const QPlatformScreen *ps = screen->handle();
                QPoint nativePos = cursor->pos();
                ps = ps->screenForPosition(nativePos);
                return QHighDpi::fromNativePixels(nativePos, ps->screen());
            }
        }
        return QGuiApplicationPrivate::lastCursorPosition.toPoint();
    }
    

    The last line would explain why I get repeated values outside an application window, but why would it need to execute that return statement, rather than the one in the if statement?

    jsulmJ 1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      In linux every script-kiddie run project wants control of your desktop, because "Their desktop is the best". Unforuntately this has led to many abominations with regard of getting real information out of the windowing system...and this wayland crap is just going to make it worse. My advice is to ditch anything having to do with gnome and use a simple X11 window manager like fvwm or twm.

      If you meet the AI on the road, kill it.

      N 1 Reply Last reply
      0
      • N normvcr

        Recently switched to Fedora 32 x86-64 with QT5.13.2, and, now, QCursor::pos() is not returning screen coordinates. Instead, it has the following behaviour:

        1. When inside a QT application window of the application that calls QCursor::pos(), the returned coordinates are relative to the application window.
        2. When outside a QT application window, the returned coordinates are constant -- whatever was last returned when it was inside a QT application window.

        The doc says, The position is queried from the windowing system, so I suppose I need to set some flag somewhere??

        My distro does not supply a debuginfo version of the qt5 libraries, but I did check the source code for QCursor::pos():

        QPoint QCursor::pos(const QScreen *screen)
        {
            if (screen) {
                if (const QPlatformCursor *cursor = screen->handle()->cursor()) {
                    const QPlatformScreen *ps = screen->handle();
                    QPoint nativePos = cursor->pos();
                    ps = ps->screenForPosition(nativePos);
                    return QHighDpi::fromNativePixels(nativePos, ps->screen());
                }
            }
            return QGuiApplicationPrivate::lastCursorPosition.toPoint();
        }
        

        The last line would explain why I get repeated values outside an application window, but why would it need to execute that return statement, rather than the one in the if statement?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @normvcr Can you try with a more recent Qt version? Also, can you try with Qt provided by your Linux distribution?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        N 1 Reply Last reply
        0
        • jsulmJ jsulm

          @normvcr Can you try with a more recent Qt version? Also, can you try with Qt provided by your Linux distribution?

          N Offline
          N Offline
          normvcr
          wrote on last edited by
          #4

          @jsulm This is the QT of my distro installer

          1 Reply Last reply
          0
          • Kent-DorfmanK Kent-Dorfman

            In linux every script-kiddie run project wants control of your desktop, because "Their desktop is the best". Unforuntately this has led to many abominations with regard of getting real information out of the windowing system...and this wayland crap is just going to make it worse. My advice is to ditch anything having to do with gnome and use a simple X11 window manager like fvwm or twm.

            N Offline
            N Offline
            normvcr
            wrote on last edited by
            #5

            @Kent-Dorfman That was exactly the problem. QCursor::pos() works correctly under GNOME classic and GNOME xorg, but not under default GNOME. Many thinks.

            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