Qt 自定义 浮动水面 效果 进度条

python 复制代码
import numpy as np
from PySide6.QtCore import QRect, Qt, QTimer, QPointF
from PySide6.QtGui import QFont, QBrush, QColor, QPainter, QPainterPath, QPen, QLinearGradient, QConicalGradient, QPolygonF, QPointFList
from PySide6.QtWidgets import QApplication, QFrame, QPushButton, QWidget, QLineEdit, QGraphicsBlurEffect, QLabel
import math
import PySide6
import math

class ButtonPush4(QFrame):
    def __init__(self, parent = None):
        super(ButtonPush4, self).__init__(parent)
        self.ui()

    def ui(self):
        self.setGeometry(QRect(0, 0, 300, 300));
        self.timer = QTimer(self);
        self.timer.timeout.connect(self.slot_time_out)
        self.timer.start(150)
        self.cur_height = 0

    def slot_time_out(self):
        self.cur_height += 4
        if( self.cur_height >= min( self.height(), self.width())):
            self.cur_height = 0

        self.update()

    def paintEvent(self, event):
        super(ButtonPush4, self).paintEvent(event);
        painter = QPainter(self)
        brush = QBrush(QColor(0, 0, 0, 0));
        # painter.setBrush(brush);
        painter.fillRect(self.rect(), brush);


        path = QPainterPath()
        r = min([ self.width(), self.height()])
        path.addEllipse( 0, 0, r, r);
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setPen(Qt.NoPen)
        painter.setClipPath(path)

        y_offset = self.height() - self.cur_height
        y = np.sin( 2 * np.pi *  np.linspace(0, 10, 3)/10 + np.random.random(1)) * 10 + y_offset
        x = np.arange( len(y) ) * self.width()/( len(y) -1);
        path = QPainterPath( QPointF( x[0], y[0]));
        for i in range( len(y) - 1):
            sp = QPointF( x[i], y[i])
            ep = QPointF( x[i+1], y[i +1])
            c1 = QPointF( (sp.x() + ep.x())/2 , sp.y())
            c2 = QPointF( (sp.x() + ep.x())/2, ep.y())
            path.cubicTo( c1, c2, ep);

        path.lineTo( QPointF( self.width(), self.height()))
        path.lineTo( QPointF( 0, self.height()))
        path.lineTo( QPointF( 0, y_offset))

        pen = QPen( QColor(255, 255, 0))
        pen.setWidth(1)
        painter.setPen( pen)
        painter.setBrush( QBrush(QColor(125, 125,255)))
        painter.drawPath(path)





if __name__ == '__main__':
    app = QApplication()
    w = QWidget();
    w.resize(300, 300)
    # w.setStyleSheet('QWidget{background-color:#000000}')

    btn = ButtonPush4(w)

    w.show()
    app.exec()

效果图如下:

相关推荐
MediaTea11 分钟前
大学 Python 编程基础(合集)
开发语言·python
墨雪不会编程11 分钟前
C++ string 详解:STL 字符串容器的使用技巧
java·开发语言·c++
悲喜自渡72115 分钟前
Python 编程(gem5 )
java·linux·开发语言
运维行者_1 小时前
OPM 与传统管理工具的区别,在网络修复与自动化运维方面的优势在哪里?
运维·服务器·开发语言·网络·自动化·php·ssl
广州灵眸科技有限公司2 小时前
瑞芯微(EASY EAI)RV1126B 音频输入
linux·开发语言·网络·音视频
吃喝不愁霸王餐APP开发者2 小时前
基于Spring Cloud Gateway实现对外卖API请求的统一鉴权与流量染色
java·开发语言
心疼你的一切3 小时前
三菱FX5U PLC与C#通信开发指南
开发语言·单片机·c#
Tim_103 小时前
【C++入门】04、C++浮点型
开发语言·c++
@淡 定3 小时前
Java内存模型(JMM)详解
java·开发语言
谈笑也风生3 小时前
经典算法题型之复数乘法(二)
开发语言·python·算法