pyqt5正在加载界面

效果

在这里插入图片描述
图像会一直渐变旋转

实现

from PyQt5 import QtCore
from PyQt5.QtCore import QPoint, Qt
from PyQt5.QtGui import QPainter, QColor, QPen
from PyQt5.QtWidgets import QDialog
from ui_loading_widget import Ui_LoadingWidget
import math


class LoadingWidget(QDialog, Ui_LoadingWidget):
    def __init__(self):
        super(LoadingWidget, self).__init__()
        self.setupUi(self)
        self.offset = 0
        # 定时器
        self.startTimer(50)
        self.setFixedSize(150, 150)
        self.setWindowFlags(QtCore.Qt.FramelessWindowHint | Qt.Tool | Qt.WindowCloseButtonHint | Qt.WindowStaysOnTopHint)
        self.setAttribute(Qt.WA_TranslucentBackground, True)

    def timerEvent(self, evt):
        self.offset += 1
        if self.offset > 11:
            self.offset = 0
        self.update()

    def paintEvent(self, evt):
        painter = QPainter(self)
        # 动反锯齿
        painter.setRenderHint(QPainter.Antialiasing, True)
        width = self.width()
        height = self.height()
        painter.translate(width >> 1, height >> 1)

        offset_dest = (width - 30) / 2
        painter.setPen(QPen(Qt.NoPen))
        # 计算小圆坐标
        for i in range(3):
            point = QPoint(0, 0)
            painter.setBrush(QColor(50 + i * 50, 20 + i * 90, 40 + i * 5, 80 + i * 80))
            point.setX(offset_dest * math.sin((-self.offset + i) * math.pi / 6))
            point.setY(offset_dest * math.cos((-self.offset + i) * math.pi / 6))
            painter.drawEllipse(point.x() - 10, point.y() - 10, 20, 20)

        for i in range(9):
            point = QPoint(0, 0)
            painter.setBrush(QColor(255, 190 - i * 20, i * 15, 255 - i * 32))
            point.setX(offset_dest * math.sin((-self.offset + i + 3) * math.pi / 6))
            point.setY(offset_dest * math.cos((-self.offset + i + 3) * math.pi / 6))
            painter.drawEllipse(point.x() - 10, point.y() - 10, 20, 20)

使用

self.load_widget = LoadingWidget()
self.load_widget.show()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值