PyQt 简单进度条

参照jacklam718的代码。

效果:

123.png
# -*- 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_())

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,786评论 25 709
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,262评论 4 61
  • 日子如流水,从指缝流过,想挽回点什么,却两手空空。今天又回到十五班,要讲孝经,天啊,哪里忙过来了呀,这不是自己找事...
    不二努力阅读 158评论 3 0
  • 没有同学的强力推荐,也没有特意的百度搜索,仅仅是因为心理课上的需要,我就这样“草率”的和《丈夫得了抑郁症》这部电影...
    安亦欢阅读 1,218评论 0 4
  • 我自认为自己属于开悟比较晚的人,过去的多年时间里,我一直信奉“努力至上”论,中毒“成功学”,看到和优秀的人的差距,...
    美丽心婷阅读 404评论 1 2