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()

效果图如下:

相关推荐
upgrador1 分钟前
基础知识:C++ STL构造函数的左闭右开惯例及其实现原理
开发语言·c++
yoothey1 小时前
报废审批流规则引擎设计——责任链模式完整实现
linux·开发语言·bash
尘中远1 小时前
【Qwt 7.0 系列】坐标轴与刻度系统 —— 刻度引擎、网格、图例与刻度朝内
qt·数据可视化·qcustomplot·qwt·工业软件·科学绘图
geovindu1 小时前
python: Functional Options Pattern
开发语言·后端·python·设计模式·惯用法模式·函数式选项模式
wuyk5551 小时前
24. C 语言模块化:不是拆几个.c 文件那么简单
c语言·开发语言·stm32·单片机
凯瑟琳.奥古斯特2 小时前
K次取反最大化数组和解法(力扣1005)
开发语言·c++·算法·leetcode·职场和发展
AC赳赳老秦2 小时前
防火墙规则批量配置实战:OpenClaw 自动生成模板、批量下发与合规性校验全解析
java·开发语言·人工智能·python·github·php·openclaw
☆cwlulu3 小时前
调试排查工具介绍(gdb、strace、Valgrind等)
开发语言·c++·嵌入式硬件·ubuntu
C语言小火车3 小时前
C++ 快速排序(Quick Sort)深度精讲:分治思想、Lomuto 分区法及三数取中优化,面试手撕必会
c语言·开发语言·c++·面试·排序算法·快速排序
sycmancia3 小时前
Qt——多线程间的互斥
开发语言·qt