参照jacklam718的代码。
效果:
# -*- coding: utf-8 -*-
import sys
import random
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class BaseProgressDialog(QMainWindow):
def __init__(self, parent=None):
super(self.__class__, self).__init__(parent)
self.resize(500, 250)
w = QWidget()
self.scroll = QScrollArea() # 滚动条
self.scroll.setWidgetResizable(True)
self.scroll.setWidget(w)
self.setCentralWidget(self.scroll)
self.layout = QVBoxLayout()
self.layout.setContentsMargins(10, 10, 10, 10)
self.layout.setAlignment(Qt.AlignTop)
# w.setMinimumSize(500,1000) # 设置显示部件的绝对大小
w.setLayout(self.layout)
def add(self, text, color, number):
label = QLabel(self.tr(text))
label.setStyleSheet("font-weight: bold;")
progressbar=QProgressBar()
progressbar.setValue(number)
style = """
QProgressBar {
border: 2px solid grey;
border-radius: 5px;
text-align: center;
}
QProgressBar::chunk {
background-color: #%s;
width: 20px;
}""" % color
progressbar.setStyleSheet(style)
self.layout.addWidget(label)
self.layout.addWidget(progressbar)
if __name__ == '__main__':
app = QApplication(sys.argv)
progress = BaseProgressDialog()
blue, green = '88B0EB', '37DA7E'
for i in range(5):
progress.add('下载',green, random.randint(0,100))
for j in range(5):
progress.add('上传',blue, random.randint(0,100))
progress.show()
sys.exit(app.exec_())