024_Progress进度条

1. Progress进度条

1.1. Progress进度条, 用于展示操作进度, 告知用户当前状态和预期。

1.2. Attributes

参数

说明

类型

可选值

默认值

percentage

百分比(必填)

number

0-100

0

type

进度条类型

string

line/circle/dashboard

line

stroke-width

进度条的宽度, 单位px

number

6

text-inside

进度条显示文字内置在进度条内(只在type=line时可用)

boolean

false

status

进度条当前状态

string

success/exception/warning

color

进度条背景色(会覆盖status状态颜色)

string/function/array

''

width

环形进度条画布宽度(只在type为circle或dashboard时可用)

number

126

show-text

是否显示进度条文字内容

boolean

true

stroke-linecap

circle/dashboard类型路径两端的形状

string

butt/round/square

round

format

指定进度条文字内容

function(percentage)

2. Progress进度条例子

2.1. 使用脚手架新建一个名为element-ui-progress的前端项目, 同时安装Element插件。

2.2. 编写index.js 

import Vue from 'vue'
import VueRouter from 'vue-router'
import Progress from '../components/Progress.vue'
import ColorProgress from '../components/ColorProgress.vue'
import DashboardProgress from '../components/DashboardProgress.vue'

Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/Progress' },
  { path: '/Progress', component: Progress },
  { path: '/ColorProgress', component: ColorProgress },
  { path: '/DashboardProgress', component: DashboardProgress }
]

const router = new VueRouter({
  routes
})

export default router

2.3. 在components在新建Progress.vue

<template>
  <div>
    <h1>线形进度条</h1>
    <h4>Progress组件设置percentage属性即可, 表示进度条对应的百分比, 必填, 必须在0-100。通过format属性来指定进度条文字内容。</h4>
    <el-progress :percentage="50"></el-progress>
    <el-progress :percentage="100" :format="format"></el-progress>
    <el-progress :percentage="100" status="success"></el-progress>
    <el-progress :percentage="100" status="warning"></el-progress>
    <el-progress :percentage="50" status="exception"></el-progress>

    <h1>百分比内显-百分比不占用额外控件, 适用于文件上传等场景</h1>
    <h4>Progress组件可通过stroke-width属性更改进度条的高度, 并可通过text-inside属性来将进度条描述置于进度条内部。</h4>
    <el-progress :text-inside="true" :stroke-width="26" :percentage="70"></el-progress>
    <el-progress :text-inside="true" :stroke-width="24" :percentage="100" status="success"></el-progress>
    <el-progress :text-inside="true" :stroke-width="22" :percentage="80" status="warning"></el-progress>
    <el-progress :text-inside="true" :stroke-width="20" :percentage="50" status="exception"></el-progress>

    <h1>环形进度条</h1>
    <h4>Progress组件可通过type属性来指定使用环形进度条, 在环形进度条中, 还可以通过width属性来设置其大小。</h4>
    <el-progress type="circle" :percentage="0"></el-progress>
    <el-progress type="circle" :percentage="25"></el-progress>
    <el-progress type="circle" :percentage="100" status="success"></el-progress>
    <el-progress type="circle" :percentage="70" status="warning"></el-progress>
    <el-progress type="circle" :percentage="50" status="exception"></el-progress>
  </div>
</template>

<script>
export default {
  methods: {
    format (percentage) {
      return percentage === 100 ? '满' : `${percentage}%`
    }
  }
}
</script>

<style scoped>
.el-progress + .el-progress {
  margin-top: 20px;
}
.el-progress--circle + .el-progress--circle {
  margin-left: 20px;
}
</style>

2.4. 在components在新建ColorProgress.vue

<template>
  <div>
    <h1>自定义颜色</h1>
    <h4>可以通过color设置进度条的颜色, color可以接受颜色字符串, 函数和数组。</h4>
    <el-progress :percentage="percentage" :color="customColor"></el-progress>
    <el-progress :percentage="percentage" :color="customColorMethod"></el-progress>
    <el-progress :percentage="percentage" :color="customColors"></el-progress>
    <div>
      <el-button-group>
        <el-button icon="el-icon-minus" @click="decrease"></el-button>
        <el-button icon="el-icon-plus" @click="increase"></el-button>
      </el-button-group>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      percentage: 20,
      customColor: '#409eff',
      customColors: [
        { color: '#f56c6c', percentage: 20 },
        { color: '#e6a23c', percentage: 40 },
        { color: '#5cb87a', percentage: 60 },
        { color: '#1989fa', percentage: 80 },
        { color: '#6f7ad3', percentage: 100 }
      ]
    }
  },
  methods: {
    customColorMethod (percentage) {
      if (percentage < 30) {
        return '#909399'
      } else if (percentage < 70) {
        return '#e6a23c'
      } else {
        return '#67c23a'
      }
    },
    increase () {
      this.percentage += 10
      if (this.percentage > 100) {
        this.percentage = 100
      }
    },
    decrease () {
      this.percentage -= 10
      if (this.percentage < 0) {
        this.percentage = 0
      }
    }
  }
}
</script>

<style scoped>
.el-progress + .el-progress {
  margin-top: 20px;
}
</style>

2.5. 在components在新建DashboardProgress.vue

<template>
  <div>
    <h1>仪表盘形进度条</h1>
    <h4>通过type属性来指定使用仪表盘形进度条。</h4>
    <el-progress type="dashboard" :percentage="percentage" :color="colors"></el-progress>
    <div>
      <el-button-group>
        <el-button icon="el-icon-minus" @click="decrease"></el-button>
        <el-button icon="el-icon-plus" @click="increase"></el-button>
      </el-button-group>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      percentage: 10,
      colors: [
        { color: '#f56c6c', percentage: 20 },
        { color: '#e6a23c', percentage: 40 },
        { color: '#5cb87a', percentage: 60 },
        { color: '#1989fa', percentage: 80 },
        { color: '#6f7ad3', percentage: 100 }
      ]
    }
  },
  methods: {
    increase () {
      this.percentage += 10
      if (this.percentage > 100) {
        this.percentage = 100
      }
    },
    decrease () {
      this.percentage -= 10
      if (this.percentage < 0) {
        this.percentage = 0
      }
    }
  }
}
</script>

2.6. 访问http://localhost:8080/#/Progress

2.7. 访问http://localhost:8080/#/ColorProgress 

2.8. 访问http://localhost:8080/#/DashboardProgress 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是使用 PyQt5 和 tqdm 模块实现的更新进度条示例代码: ```python import sys from PyQt5.QtWidgets import QApplication, QWidget, QProgressBar, QPushButton from PyQt5.QtCore import QThread, pyqtSignal from tqdm import tqdm class ProgressThread(QThread): progress_signal = pyqtSignal(int) def __init__(self, total): super().__init__() self.total = total def run(self): for i in tqdm(range(self.total)): self.progress_signal.emit(i) class ProgressBar(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): self.setGeometry(100, 100, 300, 100) self.setWindowTitle('Progress Bar') self.progress_bar = QProgressBar(self) self.progress_bar.setGeometry(20, 20, 260, 20) self.start_button = QPushButton('Start', self) self.start_button.setGeometry(20, 60, 75, 23) self.start_button.clicked.connect(self.start_progress) self.stop_button = QPushButton('Stop', self) self.stop_button.setGeometry(100, 60, 75, 23) self.stop_button.clicked.connect(self.stop_progress) self.show() def start_progress(self): self.thread = ProgressThread(100) self.thread.progress_signal.connect(self.update_progress) self.thread.start() def stop_progress(self): self.thread.terminate() def update_progress(self, value): self.progress_bar.setValue(value) if __name__ == '__main__': app = QApplication(sys.argv) bar = ProgressBar() sys.exit(app.exec_()) ``` 这个示例程序创建了一个简单的窗口,包含一个进度条和两个按钮。当用户点击“Start”按钮时,程序将启动一个后台线程来执行进度条更新任务。当用户点击“Stop”按钮时,程序将停止后台线程。进度条更新任务使用 tqdm 模块来显示进度条。通过使用 pyqtSignal,我们可以在后台线程和主线程之间进行通信,从而实现进度条的更新。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值