How can I change the cursor shape with PyQt?(如何使用 PyQt 更改光标形状?)
问题描述
我有一个简单的应用程序,它运行的进程可能会持续几分钟才能完成.我正在尝试向用户提供它正在处理请求的指示 - 例如将光标更改为沙漏.
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 更改光标形状?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 PyQt 更改光标形状?
基础教程推荐
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 筛选NumPy数组 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01