1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import division
# python v2.7
import sys
from PyQt4 import QtGui, QtCore
class ProgressBar(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.setWindowTitle('Petit test de QProgressBar')
self.pbar = QtGui.QProgressBar(self)
self.pbar2 = QtGui.QProgressBar(self)
self.pbar2.setMinimum(0)
self.pbar2.setMaximum(0)
self.button = QtGui.QPushButton('Start', self)
self.connect(self.button, QtCore.SIGNAL('clicked()'), self.onStart)
self.timer = QtCore.QBasicTimer()
self.step = 0;
posit = QtGui.QGridLayout()
posit.addWidget(self.pbar, 0, 0)
posit.addWidget(self.pbar2, 1, 0)
posit.addWidget(self.button, 2, 0)
self.setLayout(posit)
def timerEvent(self, event):
if self.step >= 100:
self.timer.stop()
return
self.step = self.step + 1
self.pbar.setValue(self.step)
def onStart(self):
if self.timer.isActive():
self.timer.stop()
self.button.setText('Start')
else:
self.timer.start(100, self)
self.button.setText('Stop')
app = QtGui.QApplication(sys.argv)
fen = ProgressBar()
fen.show()
app.exec_() |
Partager