Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Make the cursor on the screen invisible after it has stopped



  • first, sorry for my poor english !

    I want to make the cursor on the screen become invisible after it has stopped moving for 10s. I think this problem can be solved easily if there is a signal like positionChanged(QPoint lastPos , QPoint currentPos) existed,lastPos means the last position of the cursor (hot spot) of the primary screen in global screen coordinates, currentPos means the current position, this signal should be emitted once the cursor stopped moving .Note the Mouse move events here should occur even when a mouse button is not pressed down, i.e. there is mouse tracking with cursor.In Qt, mouse tracking could be enabled with QWidget::setMouseTracking(), however my problem is not restricted to Qt, it is system wide, I want to do this on Windows now ,anyone knows how to enable mouse tracking here ?
    any other solution is also welcome !



  • Please have a look at the documentation of class "QCursor":http://qt-project.org/doc/qt-5/QCursor.html. It is possible to obtain the coordinates of the cursor in global screen coordinates using method "pos()":http://qt-project.org/doc/qt-5/qcursor.html#pos. The same class allows you to change the shape or the cursor or to create a cursor with custom image.



  • yes,I konw it ,the problem I am facing is how to detect the motion of the cursor on the screen,any idea ?
    [quote author="leon.anavi" date="1397839345"]Please have a look at the documentation of class "QCursor":http://qt-project.org/doc/qt-5/QCursor.html. It is possible to obtain the coordinates of the cursor in global screen coordinates using method "pos()":http://qt-project.org/doc/qt-5/qcursor.html#pos. The same class allows you to change the shape or the cursor or to create a cursor with custom image.[/quote]



  • I would try to use a
    @
    QTimer
    @
    Run it each 10 seconds and compare the screen coordinates with the previous QTimer::timeout signal.



  • [quote author="andreyc" date="1397882114"]I would try to use a
    @
    QTimer
    @
    Run it each 10 seconds and compare the screen coordinates with the previous QTimer::timeout signal.
    [/quote]

    Yes, this is a simple and nice idea but it seems not very precise. The approach using a QTimer just to check mouse coordinates on each 10s will check whether the mouse has been moved in the last 10s but it will not detect whether the mouse has not been moved for 10s. I hope you understand the difference which I try to explain :)

    Since @redstoneleo is trying to implement a solution for windows he can combine Qt source code with hook to the Windows APIs and to handle "WM_MOUSEMOVE":http://msdn.microsoft.com/en-us/library/windows/desktop/ms645616(v=vs.85).aspx. Here are a couple of examples:



  • I want to hide system cursor for 10s for some reason ,but I found

    cursor.setShape(Qt.BlankCursor)

    can only hide mouse cursor that is associated with QWidgets ,not in system wide ,i.e. when mouse cursor is hovering on QWidgets, it is invisible ,otherwise it is visible ,so is there any way to hide system cursor in system wide?



  • You need to use the OS API for this.


Log in to reply