效果:
image# -*- 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_())
作者:qdsfdhvh
链接:https://www.jianshu.com/p/34096a8632aa
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
网友评论