我一直在寻找任何动画的例子QProgressBar
,但我找不到任何东西。默认情况下,它有一个较浅的模糊绿色条纹的输血动画:
但是当它改变时StyleSheet
,它就会消失。我只能qlineargradient
根据进度找到具有和更改颜色的样式,但这不是如何制作像默认进度条或任何其他内容那样的静态动画,只是为了表明它正在加载。
QProgressBar
安装和安装的最小可重现示例StyleSheet
:
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import QTimer
STYLE = '''QProgressBar {
text-align: center;
background-color: black;
border: solid grey;
border-radius: 15px;
color: white;
}
QProgressBar::chunk {
background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 1,stop: 0 white, stop: 0.4 gray,stop: 1 green);
border-radius :15px;
} '''
count = 0
class Window(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("ProgressBar widget")
self.setGeometry(350, 150, 500, 500)
self.UI()
def UI(self):
vbox = QVBoxLayout()
hbox = QHBoxLayout()
self.progressBar = QProgressBar()
btnStart = QPushButton("Start")
btnStart.clicked.connect(self.timerStart)
btnStop = QPushButton("Stop")
btnStop.clicked.connect(self.timerStop)
self.timer = QTimer()
self.timer.setInterval(100)
self.timer.timeout.connect(self.runProgressBar)
vbox.addWidget(self.progressBar)
vbox.addLayout(hbox)
hbox.addWidget(btnStart)
hbox.addWidget(btnStop)
self.setLayout(vbox)
self.progressBar.setFixedHeight(30)
self.progressBar.setStyleSheet(STYLE)
self.show()
def runProgressBar(self):
global count
count += 1
print(count)
self.progressBar.setValue(count)
if count == 100:
self.timer.stop()
def timerStart(self):
self.timer.start()
def timerStop(self):
self.timer.stop()
def main():
App = QApplication(sys.argv)
window = Window()
sys.exit(App.exec_())
if __name__ == '__main__':
main()
试试这样:
主文件
样式动画.py
试试这样: