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. Moving the cursor
Qt 6.11 is out! See what's new in the release blog

Moving the cursor

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

    So say I open a new window. I want the mouse cursor to move to a random position on the window that was spawned ( the location doesn't really matter ).

    Is it possible?

    I tried using QCursor's setPos function and I had the position of the widget that was spawned with this->pos();
    but it didn't work

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

      Hi,

      How exactly did you implement that ?

      On a side note, you should really think about that idea. People usually don't find it nice that their cursor starts moving around without them asking for some sort of assistance for that.

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

      F 1 Reply Last reply
      2
      • SGaistS SGaist

        Hi,

        How exactly did you implement that ?

        On a side note, you should really think about that idea. People usually don't find it nice that their cursor starts moving around without them asking for some sort of assistance for that.

        F Offline
        F Offline
        Fuchsiaff
        wrote on last edited by
        #3

        @SGaist

        I'm implementing it like this:

            def move_cursor(self, x, y):
        
                screen = QGuiApplication.primaryScreen()
        
                cursor = QCursor()
        
                cursor.setPos(x, y)
        

        If I replace cursor.setPos(x, y) with cursor.setPos(screen, x, y) then it errors and says:

        TypeError: arguments did not match any overloaded call:
         setPos(int, int): argument 1 has unexpected type 'QScreen'
         setPos(QPoint): argument 1 has unexpected type 'QScreen'```
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          setPos is a static method.

          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

          F 1 Reply Last reply
          3
          • SGaistS SGaist

            setPos is a static method.

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

            F Offline
            F Offline
            Fuchsiaff
            wrote on last edited by
            #5

            @SGaist

            When I tested it in pycharm it didn't work but after running the script from a terminal it works but the cursor gets put in a wrong position. I will find a fix for that later but thanks for trying to help!

            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