PyQt5:如何在多次覆盖后恢复默认光标?

2024-06-28 20:46:06 发布

您现在位置:Python中文网/ 问答频道 /正文

是否有方法将鼠标光标图标行为重置为windows默认值

当一个长进程运行时,我想显示一个等待的鼠标光标图标,它完成了任务:

# Set the mouse cursor to wait cursor
QtWidgets.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))

# Long process start
# Long process end

#reset mouse cursor to default behaviour
QtWidgets.QApplication.restoreOverrideCursor()

问题在于,在漫长的过程中,我运行的方法或事件或任何同时调用setOverrideCursors的东西:

# Set the mouse cursor to wait cursor
QtWidgets.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))

# Long process start
    # In the long process theres a method or event or whatever that calls again the wait cursor
    # and wait cursor becomes the overwritten mouse cursor
    QtWidgets.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
    # Some code running...
    QtWidgets.QApplication.restoreOverrideCursor()
# Long process end

# the restoreOverrideCursor() restores the wait cursor instead of the default mouse cursor behaviour 
# and the mouse icon just spinning forever
QtWidgets.QApplication.restoreOverrideCursor()

我尝试了这个,而不是restoreOverrideCursor():

QtWidget.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))

但问题是,它会用箭头光标、示例窗口大小调整图标等编写每个行为

有没有办法恢复PyQt5中默认的鼠标行为


Tags: the鼠标qtprocesscursorlongwaitqtgui