QtGui.QProgressBar
A progress bar is a widget that is used when we process lengthy tasks. It is animated so that the user knows that the task is progressing. The QtGui.QProgressBar widget provides a horizontal or vertical progress bar in PyQt4 toolkit. The programmer can set the minimum and maximum value for the progress bar. The default values are 0 and 99.
#!/usr/bin/python
# -*- coding: utf-8 -*- """
ZetCode PyQt4 tutorial This example shows a QtGui.QProgressBar widget. author: Jan Bodnar
website: zetcode.com
last edited: September 2011
""" import sys
from PyQt4 import QtGui, QtCore class Example(QtGui.QWidget): def __init__(self):
super(Example, self).__init__() self.initUI() def initUI(self): self.pbar = QtGui.QProgressBar(self)
self.pbar.setGeometry(30, 40, 200, 25) self.btn = QtGui.QPushButton('Start', self)
self.btn.move(40, 80)
self.btn.clicked.connect(self.doAction) self.timer = QtCore.QBasicTimer()
self.step = 0 self.setGeometry(300, 300, 280, 170)
self.setWindowTitle('QtGui.QProgressBar')
self.show() def timerEvent(self, e): if self.step >= 100: self.timer.stop()
self.btn.setText('Finished')
return self.step = self.step + 1
self.pbar.setValue(self.step) def doAction(self): if self.timer.isActive():
self.timer.stop()
self.btn.setText('Start') else:
self.timer.start(100, self)
self.btn.setText('Stop') def main(): app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_()) if __name__ == '__main__':
main()
In our example we have a horizontal progress bar and a push button. The push button starts and stops the progress bar.
self.pbar = QtGui.QProgressBar(self)
This is a QtGui.QProgressBar constructor.
self.timer = QtCore.QBasicTimer()
To activate the progress bar, we use a timer object.
self.timer.start(100, self)
To launch a timer event, we call its start() method. This method has two parameters: the timeout and the object which will receive the events.
def timerEvent(self, e):
if self.step >= 100:
self.timer.stop()
self.btn.setText('Finished')
return
self.step = self.step + 1
self.pbar.setValue(self.step)
Each QtCore.QObject and its descendants have a timerEvent() event handler. In order to react to timer events, we reimplement the event handler.
def doAction(self):
if self.timer.isActive():
self.timer.stop()
self.btn.setText('Start')
else:
self.timer.start(100, self)
self.btn.setText('Stop')
Inside the doAction() method, we start and stop the timer.
Figure: QtGui.QProgressBar
QtGui.QProgressBar的更多相关文章
- PyQt4进度条QProgressBar
当我们在处理一个好事较长的任务时,可能就会用到进度条部件.因为使用进度条可以形象告诉用户当前的人物正在进行中.PyQt4工具包提供了水平和垂直两种类型的进度条部件.我们可以设置进度条的最大和最小值,默 ...
- Pyqt Smtplib实现Qthread多线程发送邮件
一. smtplib 的介绍 smtplib.SMTP([host[, port[, local_hostname[, timeout]]]]) SMTP类构造函数,表示与SMTP服务器之间的连接 ...
- pyqt4_应用例子(计算器,对话框,进度条,日历等等)
sklearn实战-乳腺癌细胞数据挖掘(博客主亲自录制视频教程) https://study.163.com/course/introduction.htm?courseId=1005269003&a ...
- ZetCode PyQt4 tutorial widgets I
#!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...
- qt4.8转qt5.4
1.头文件包含 #include <QtGui/QProgressBar> #include <QtGui/QProgressDialog> #include ...
- PYQT4 Python GUI 编写与 打包.exe程序
工作中需要开发一个小工具,简单的UI界面可以很好的提高工具的实用性,由此开启了我的第一次GUI开发之旅,下面将自己学习的心得记录一下,也做为学习笔记吧!!! 参考:http://www.qaulau. ...
- PyQt4 进度条和日历 代码
# -*- coding: utf-8 -*- """ ------------------------------------------------- File Na ...
- 读Pyqt4教程,带你入门Pyqt4 _007
QSlider 滑块是由一个简单的滑柄的窗口组件.该滑柄可以前后拖动,通过这种方式我们可以为特定任务选择值.有时候使用滑块比简单提供数值或使用微调框(spin box)更自然. QLabel 显示文字 ...
- 【PyQt5-Qt Designer】QProgressBar() 进度条
QProgressBar() 进度条 QProgressBar简介 QProgressBar小部件提供了一个水平或垂直的进度条. 进度条用于向用户指示操作的进度,并向他们保证应用程序仍在运行. 进度条 ...
随机推荐
- loj115 无源汇有上下界可行流
link 题意&题解 code: #include<bits/stdc++.h> #define rep(i,x,y) for (int i=(x);i<=(y);i++) ...
- poj 3261 求可重叠的k次最长重复子串
题意:求可重叠的k次最长重复子串的长度 链接:点我 和poj1743差不多 #include<cstdio> #include<iostream> #include<al ...
- bzoj1004 purfer 序列
之前没不知道这个数列. 一个purfer序列与一棵树一一对应. 长度为n的purfer的集合: A = { s | s is a sequence and a∈[1,len(s)+2] 一个直接的结论 ...
- Codeforces Round #299 (Div. 2) B. Tavas and SaDDas 水题
B. Tavas and SaDDas Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/535/p ...
- codevs 1060 搞笑运动会 dp
1060 搞笑世界杯 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codevs.cn/problem/1060/ Description ...
- GIT 提交步骤
1.提交 git add .
- SecureCRT也能和Xshell一样批量导入主机
在Xshell可以像这样一个文件批量导入主机: https://blog.netsarang.com/91/importing-csv-formatted-host-information-to-xs ...
- STM32 USB VBUS 监控
OTG_FS general core configuration register (OTG_FS_GCCFG) Bit 21 NOVBUSSENS: VBUS sensing disable op ...
- 记一次压力测试和对nginx/tomcat配置的调整
原文地址:还没找到 是一个web系统,前端使用nginx做为反向代理,处理https,并将请求转发给后端的tomcat服务. 压力测试工具选择了jmeter. 首先简单介绍一下jmeter. 它是ap ...
- 从Log4j迁移到LogBack的理由
英文原文:Reasons to prefer logback over log4j 无论从设计上还是实现上,Logback相对log4j而言有了相对多的改进.不过尽管难以一一细数,这里还是列举部分理由 ...