Results 1 to 3 of 3

Thread: QCursor::setPos makes cursor inactive for ~200ms

  1. #1
    Join Date
    Jul 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question QCursor::setPos makes cursor inactive for ~200ms

    Hi there,

    I have some code that uses a QTimer to get the current cursor position every x milliseconds. Every n runs of this, it resets the cursor to the middle of the screen using the static QCursor::setPos(int x, int y). However, queries on the position of the cursor for around the next 200ms show it being in the middle of the screen, despite me flailing the mouse around wildly. You can even see it "stick" in the middle for a short while.

    Does anyone know why this happens or how I can fix it?

    I'm using PyQt with Qt 4.4 right now. Thanks for your help.

    -tom

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QCursor::setPos makes cursor inactive for ~200ms

    Can we see some code of yours?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QCursor::setPos makes cursor inactive for ~200ms

    Here is some code that illustrates what I am talking about:

    Qt Code:
    1. import sys, os, xvis, time, math
    2. from PyQt4.QtCore import *
    3. from PyQt4.QtGui import *
    4.  
    5. class Driver(QWidget):
    6. def __init__(self, parent):
    7. QWidget.__init__(self, parent)
    8. self.setMouseTracking(True)
    9. self.last_cursor = QCursor.pos()
    10. self.last_update = 0
    11. self.reset_interval = 100
    12. self.middle_x = app.desktop().screenGeometry().width() / 2.0
    13. self.middle_y = app.desktop().screenGeometry().height() / 2.0
    14.  
    15. def get_cursor_change(self):
    16. """Return (x,y) tuple of cursor change"""
    17. self.last_update += 1
    18. cursor = QCursor.pos()
    19. diff = cursor - self.last_cursor
    20. self.last_cursor = cursor
    21. if self.last_update > self.reset_interval:
    22. # move cursor to middle of screen
    23. QCursor.setPos(self.middle_x, self.middle_y)
    24. self.last_cursor = QPoint(self.middle_x, self.middle_y)
    25. self.last_update = 0
    26. return (diff.x(), diff.y())
    27.  
    28. def mouseMoveEvent(self, event):
    29. event.accept()
    30.  
    31. class MainWindow(QMainWindow):
    32. def __init__(self, parent=None):
    33. QMainWindow.__init__(self, parent)
    34.  
    35. self.driver = Driver(self)
    36. self.setCentralWidget(self.driver)
    37.  
    38. # run loop
    39. timer = QTimer(self)
    40. self.connect(timer, SIGNAL("timeout()"), self.update)
    41. timer.start(50)
    42.  
    43. def update(self):
    44. """Gets called each iteration"""
    45. cursor_change = self.driver.get_cursor_change()
    46. print cursor_change
    47.  
    48. if __name__ == "__main__":
    49. app = QApplication(sys.argv)
    50. mainwindow = MainWindow()
    51. mainwindow.show()
    52. mainwindow.raise_()
    53. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

    and here is some sample output:

    Qt Code:
    1. ...
    2. (0, 45)
    3. (-56, 63)
    4. (-49, 18)
    5. (-59, -39)
    6. (-11, -98)
    7. (51, -30)
    8. (98, 30)
    9. (44, 68)
    10. (-59, 60)
    11. (-96, 19)
    12. (0, 0)
    13. (0, 0)
    14. (0, 0)
    15. (0, 0)
    16. (0, 0)
    17. (4, 91)
    18. (-23, 44)
    19. (-54, 3)
    20. (-98, -44)
    21. (-52, -86)
    22. (43, -76)
    23. (63, -3)
    24. (56, 47)
    25. (5, 84)
    26. (-68, 72)
    27. (-83, 18)
    28. (-109, -34)
    29. (-61, -52)
    30. (18, -44)
    31. ...
    To copy to clipboard, switch view to plain text mode 

    The above is when moving the mouse around constantly. You can see the (0,0)s occur right after the mouse is reset to the middle.

    Thanks for your help.

    -tom

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.