From 6164ef9821cf1918b1b943064af72fbc764e69e1 Mon Sep 17 00:00:00 2001 From: shuaikangzhou <863909694@qq.com> Date: Sat, 23 Dec 2023 21:45:36 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/components/QCursorGif.py | 62 ++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 app/components/QCursorGif.py diff --git a/app/components/QCursorGif.py b/app/components/QCursorGif.py new file mode 100644 index 0000000..6ba6647 --- /dev/null +++ b/app/components/QCursorGif.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Created on 2020年3月13日 +@author: Irony +@site: https://pyqt.site , https://github.com/PyQt5 +@email: 892768447@qq.com +@file: Demo.Lib.QCursorGif +@description: +""" + +try: + from PyQt5.QtCore import QTimer, Qt + from PyQt5.QtGui import QCursor, QPixmap + from PyQt5.QtWidgets import QApplication +except ImportError: + from PySide2.QtCore import QTimer, Qt + from PySide2.QtGui import QCursor, QPixmap + from PySide2.QtWidgets import QApplication +from app.resources import resource_rc + +var = resource_rc.qt_resource_name + + +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)