动态忙碌光标
BIN
Demo/Data/Images/Cursors/0.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
Demo/Data/Images/Cursors/1.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
Demo/Data/Images/Cursors/2.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
Demo/Data/Images/Cursors/3.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
Demo/Data/Images/Cursors/4.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
Demo/Data/Images/Cursors/5.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
Demo/Data/Images/Cursors/6.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
Demo/Data/Images/Cursors/7.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
46
Demo/GifCursor.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Created on 2020年3月13日
|
||||
@author: Irony
|
||||
@site: https://pyqt.site https://github.com/892768447
|
||||
@email: 892768447@qq.com
|
||||
@file: Demo.GifCursor
|
||||
@description:
|
||||
"""
|
||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton
|
||||
|
||||
from Demo.Lib.QCursorGif import QCursorGif
|
||||
|
||||
|
||||
__Author__ = 'Irony'
|
||||
__Copyright__ = 'Copyright (c) 2020'
|
||||
__Version__ = 1.0
|
||||
|
||||
|
||||
class Window(QWidget, QCursorGif):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(Window, self).__init__(*args, **kwargs)
|
||||
# 设置忙碌光标图片数组
|
||||
self.initCursor(['Data/Images/Cursors/%d.png' %
|
||||
i for i in range(8)], self)
|
||||
self.setCursorTimeout(100)
|
||||
|
||||
layout = QVBoxLayout(self)
|
||||
layout.addWidget(QPushButton(
|
||||
'start busy', self, clicked=self.startBusy))
|
||||
layout.addWidget(QPushButton(
|
||||
'stop busy', self, clicked=self.stopBusy))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
import cgitb
|
||||
sys.excepthook = cgitb.enable(1, None, 5, '')
|
||||
from PyQt5.QtWidgets import QApplication
|
||||
app = QApplication(sys.argv)
|
||||
w = Window()
|
||||
w.show()
|
||||
sys.exit(app.exec_())
|
58
Demo/Lib/QCursorGif.py
Normal file
|
@ -0,0 +1,58 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Created on 2020年3月13日
|
||||
@author: Irony
|
||||
@site: https://pyqt.site https://github.com/892768447
|
||||
@email: 892768447@qq.com
|
||||
@file: Demo.Lib.QCursorGif
|
||||
@description:
|
||||
"""
|
||||
from PyQt5.QtCore import QTimer, Qt
|
||||
from PyQt5.QtGui import QCursor, QPixmap
|
||||
from PyQt5.QtWidgets import QApplication
|
||||
|
||||
|
||||
__Author__ = 'Irony'
|
||||
__Copyright__ = 'Copyright (c) 2020'
|
||||
__Version__ = 1.0
|
||||
|
||||
|
||||
class QCursorGif:
|
||||
|
||||
def initCursor(self, cursors, parent=None):
|
||||
# 记录默认的光标
|
||||
self._oldCursor = Qt.ArrowCursor
|
||||
self.setOldCursor(parent)
|
||||
# 加载光标图片
|
||||
self._cursorImages = [
|
||||
QCursor(QPixmap(cursor)) for cursor in cursors]
|
||||
self._cursorIndex = 0
|
||||
self._cursorCount = len(self._cursorImages) - 1
|
||||
# 创建刷新定时器
|
||||
self._cursorTimeout = 200
|
||||
self._cursorTimer = QTimer(parent)
|
||||
self._cursorTimer.timeout.connect(self._doBusy)
|
||||
|
||||
def _doBusy(self):
|
||||
if self._cursorIndex > self._cursorCount:
|
||||
self._cursorIndex = 0
|
||||
QApplication.instance().setOverrideCursor(
|
||||
self._cursorImages[self._cursorIndex])
|
||||
self._cursorIndex += 1
|
||||
|
||||
def startBusy(self):
|
||||
if not self._cursorTimer.isActive():
|
||||
self._cursorTimer.start(self._cursorTimeout)
|
||||
|
||||
def stopBusy(self):
|
||||
self._cursorTimer.stop()
|
||||
QApplication.instance().setOverrideCursor(self._oldCursor)
|
||||
|
||||
def setCursorTimeout(self, timeout):
|
||||
self._cursorTimeout = timeout
|
||||
|
||||
def setOldCursor(self, parent=None):
|
||||
self._oldCursor = (parent.cursor() or Qt.ArrowCursor) if parent else (
|
||||
QApplication.instance().overrideCursor() or Qt.ArrowCursor)
|
|
@ -22,6 +22,7 @@
|
|||
- [调整窗口显示边框](#19调整窗口显示边框)
|
||||
- [判断信号是否连接](#20判断信号是否连接)
|
||||
- [调用虚拟键盘](#21调用虚拟键盘)
|
||||
- [动态忙碌光标](#22动态忙碌光标)
|
||||
|
||||
## 1、重启窗口Widget
|
||||
[运行 RestartWindow.py](RestartWindow.py)
|
||||
|
@ -215,3 +216,10 @@ PyQt 结合 Opencv 进行人脸检测;
|
|||
|
||||
![CallVirtualKeyboard1](ScreenShot/CallVirtualKeyboard1.png)
|
||||
![CallVirtualKeyboard2](ScreenShot/CallVirtualKeyboard2.png)
|
||||
|
||||
## 22、动态忙碌光标
|
||||
[运行 GifCursor.py](GifCursor.py)
|
||||
|
||||
通过定时器不停的修改光标图片来实现动态效果
|
||||
|
||||
![GifCursor](ScreenShot/GifCursor.gif)
|
BIN
Demo/ScreenShot/GifCursor.gif
Normal file
After Width: | Height: | Size: 142 KiB |
|
@ -244,6 +244,7 @@ https://pyqt.site 论坛是专门针对PyQt5学习和提升开设的网站,分
|
|||
- [背景连线动画](Demo/CircleLine.py)
|
||||
- [判断信号是否连接](Demo/IsSignalConnected.py)
|
||||
- [调用虚拟键盘](Demo/CallVirtualKeyboard.py)
|
||||
- [动态忙碌光标](Demo/GifCursor.py)
|
||||
|
||||
# QQ群
|
||||
|
||||
|
|