diff --git a/Demo/Data/Images/Cursors/0.png b/Demo/Data/Images/Cursors/0.png new file mode 100644 index 0000000..27923f3 Binary files /dev/null and b/Demo/Data/Images/Cursors/0.png differ diff --git a/Demo/Data/Images/Cursors/1.png b/Demo/Data/Images/Cursors/1.png new file mode 100644 index 0000000..e338b58 Binary files /dev/null and b/Demo/Data/Images/Cursors/1.png differ diff --git a/Demo/Data/Images/Cursors/2.png b/Demo/Data/Images/Cursors/2.png new file mode 100644 index 0000000..59ee695 Binary files /dev/null and b/Demo/Data/Images/Cursors/2.png differ diff --git a/Demo/Data/Images/Cursors/3.png b/Demo/Data/Images/Cursors/3.png new file mode 100644 index 0000000..b86d752 Binary files /dev/null and b/Demo/Data/Images/Cursors/3.png differ diff --git a/Demo/Data/Images/Cursors/4.png b/Demo/Data/Images/Cursors/4.png new file mode 100644 index 0000000..61374db Binary files /dev/null and b/Demo/Data/Images/Cursors/4.png differ diff --git a/Demo/Data/Images/Cursors/5.png b/Demo/Data/Images/Cursors/5.png new file mode 100644 index 0000000..5c2bc10 Binary files /dev/null and b/Demo/Data/Images/Cursors/5.png differ diff --git a/Demo/Data/Images/Cursors/6.png b/Demo/Data/Images/Cursors/6.png new file mode 100644 index 0000000..ab3996a Binary files /dev/null and b/Demo/Data/Images/Cursors/6.png differ diff --git a/Demo/Data/Images/Cursors/7.png b/Demo/Data/Images/Cursors/7.png new file mode 100644 index 0000000..0962be4 Binary files /dev/null and b/Demo/Data/Images/Cursors/7.png differ diff --git a/Demo/GifCursor.py b/Demo/GifCursor.py new file mode 100644 index 0000000..2dbdc52 --- /dev/null +++ b/Demo/GifCursor.py @@ -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_()) diff --git a/Demo/Lib/QCursorGif.py b/Demo/Lib/QCursorGif.py new file mode 100644 index 0000000..0ff9959 --- /dev/null +++ b/Demo/Lib/QCursorGif.py @@ -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) diff --git a/Demo/README.md b/Demo/README.md index cab8264..9fc9353 100644 --- a/Demo/README.md +++ b/Demo/README.md @@ -22,6 +22,7 @@ - [调整窗口显示边框](#19调整窗口显示边框) - [判断信号是否连接](#20判断信号是否连接) - [调用虚拟键盘](#21调用虚拟键盘) + - [动态忙碌光标](#22动态忙碌光标) ## 1、重启窗口Widget [运行 RestartWindow.py](RestartWindow.py) @@ -214,4 +215,11 @@ PyQt 结合 Opencv 进行人脸检测; 2. Linux上调用的是`florence`,`onboard`,`kvkbd`,这三种屏幕键盘需要自行安装 ![CallVirtualKeyboard1](ScreenShot/CallVirtualKeyboard1.png) -![CallVirtualKeyboard2](ScreenShot/CallVirtualKeyboard2.png) \ No newline at end of file +![CallVirtualKeyboard2](ScreenShot/CallVirtualKeyboard2.png) + +## 22、动态忙碌光标 +[运行 GifCursor.py](GifCursor.py) + +通过定时器不停的修改光标图片来实现动态效果 + +![GifCursor](ScreenShot/GifCursor.gif) \ No newline at end of file diff --git a/Demo/ScreenShot/GifCursor.gif b/Demo/ScreenShot/GifCursor.gif new file mode 100644 index 0000000..ed42f61 Binary files /dev/null and b/Demo/ScreenShot/GifCursor.gif differ diff --git a/README.md b/README.md index 989bdd2..d038768 100644 --- a/README.md +++ b/README.md @@ -244,6 +244,7 @@ https://pyqt.site 论坛是专门针对PyQt5学习和提升开设的网站,分 - [背景连线动画](Demo/CircleLine.py) - [判断信号是否连接](Demo/IsSignalConnected.py) - [调用虚拟键盘](Demo/CallVirtualKeyboard.py) + - [动态忙碌光标](Demo/GifCursor.py) # QQ群