問題描述
我有一個簡單的應用程序,它運行的進程可能會持續幾分鐘才能完成.我正在嘗試向用戶提供它正在處理請求的指示 - 例如將光標更改為沙漏.
I have a simple application that runs a process that can last for several minutes before completing. I am trying to provide an indication to the user that it is processing the request - such as changing the cursor to an hourglass.
但我不能讓它正常工作.我所有的嘗試都導致錯誤或無效.而且我似乎錯誤地調用了光標形狀,因為 PyQt4.Qt.WaitCursor
返回模塊不包含它的錯誤.
But I cannot quite get it to work right. All of my attempts have resulted in either an error or had no effect. And I seem to be calling the cursor shapes incorrectly, since PyQt4.Qt.WaitCursor
returns an error that the module does not contain it.
向用戶指示進程正在運行的正確方法是什么?
What is the correct way to indicate to the user that the process is running?
推薦答案
我認為 QApplication.setOverrideCursor 就是你要找的東西:
I think QApplication.setOverrideCursor is what you're looking for:
PyQt5:
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication
...
QApplication.setOverrideCursor(Qt.WaitCursor)
# do lengthy process
QApplication.restoreOverrideCursor()
PyQt4:
from PyQt4.QtCore import Qt
from PyQt4.QtGui import QApplication
...
QApplication.setOverrideCursor(Qt.WaitCursor)
# do lengthy process
QApplication.restoreOverrideCursor()
這篇關于如何使用 PyQt 更改光標形狀?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!