Results 1 to 4 of 4

Thread: QCursor::setPos has no effect

  1. #1
    Join Date
    Mar 2019
    Posts
    2
    Qt products
    Qt5

    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,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 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
    Join Date
    Mar 2019
    Posts
    2
    Qt products
    Qt5

    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
    554
    Thanked 86 Times in 81 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: 3rd December 2010, 00:45
  2. Replies: 1
    Last Post: 2nd July 2010, 20:47
  3. QCursor::setPos() - doesn't work
    By Piskvorkar in forum Qt Programming
    Replies: 0
    Last Post: 21st March 2010, 14:24
  4. Why QCursor setPos() dosen't work here?
    By kar98k in forum Qt Programming
    Replies: 8
    Last Post: 1st June 2007, 13:52
  5. QCursor::setPos
    By Levon Nikoghosyan in forum Qt Programming
    Replies: 1
    Last Post: 26th December 2006, 09: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.