Results 1 to 4 of 4

Thread: QCursor::setPos has no effect

  1. #1

    Default QCursor::setPos has no effect

    Hello!

    I am trying to implement a "warp mouse" effect (the mouse cursor stays in the same spot on my widget even when mouse is moving) by using QCursor::setPos but it has no effect.

    Qt Code:
    1. void QmlMouseController::warpMouse(const QPoint & p)
    2. {
    3. std::cout << "pre pos: " << QCursor::pos(0).x() << " " << QCursor::pos(0).y() << std::endl;
    4. std::cout << "warp: " << p.x() << " " << p.y() << std::endl;
    5. QCursor::setPos(QApplication::primaryScreen() ,p);
    6. std::cout << "post pos: " << QCursor::pos(0).x() << " " << QCursor::pos(0).y() << std::endl;
    7. }
    To copy to clipboard, switch view to plain text mode 

    When the above code is called with a QPoint that holds the mouse coordinates that i want to move the cursor to it prints:

    Qt Code:
    1. pre pos: -2147483648 -2147483648
    2. warp: 799 361
    3. post pos: -2147483648 -2147483648
    To copy to clipboard, switch view to plain text mode 

    QCursor:: pos returns -2147483648 and setPos has no effect ?! (all versions of setPos has been tested)
    I am calling this function from QML but i dont think that should matter.

    Running Windows 10 and Qt 5.12

    Any help and ideas are appreciated.

    Br
    --Anders

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,249
    Thanks
    36
    Thanked 1,508 Times in 1,459 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QCursor::setPos has no effect

    What if you pass a valid screen pointer to pos() instead of a null pointer. Or call the pos() overload without arguments?

    Cheers,
    _

  3. #3

    Default Re: QCursor::setPos has no effect

    Good catch However it makes no difference with any other version of pos()

    Br
    --Anders

  4. #4
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    414
    Thanked 54 Times in 50 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QCursor::setPos has no effect

    https://doc.qt.io/qt-5/qcursor.html#setPos-1

    "Note: On platforms where there is no windowing system or cursors are not available, this function may do nothing."

    Now the question is if windows falls in this category

Similar Threads

  1. QCursor::setPos() fails with x server fatal error
    By Arnaldo Diniz in forum Qt Programming
    Replies: 3
    Last Post: 2nd December 2010, 23:45
  2. Replies: 1
    Last Post: 2nd July 2010, 19:47
  3. QCursor::setPos() - doesn't work
    By Piskvorkar in forum Qt Programming
    Replies: 0
    Last Post: 21st March 2010, 13:24
  4. Why QCursor setPos() dosen't work here?
    By kar98k in forum Qt Programming
    Replies: 8
    Last Post: 1st June 2007, 12:52
  5. QCursor::setPos
    By Levon Nikoghosyan in forum Qt Programming
    Replies: 1
    Last Post: 26th December 2006, 08:16

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.