I'm learning Pyside QProgressBar
on MacOSX. When I use QProgressBar like following, it only indicate 0% or 100%. How to make a QProgressBar smoothly? Is there any way to do this?
from PySide.QtGui import QApplication, QProgressBar, QWidget
from PySide.QtCore import QTimer
import time
app = QApplication([])
pbar = QProgressBar()
pbar.setMinimum(0)
pbar.setMaximum(100)
pbar.show()
def drawBar():
global pbar
pbar.update()
t = QTimer()
t.timeout.connect(drawBar)
t.start(100)
for i in range(1,101):
time.sleep(0.1)
pbar.setValue(i)
app.exec_()
QPropertyAnimation is easy to use and it does the smooth change for you.
Edited post:
Just replace everything between pbar.show() and app.exec() by the code I suggested
Here is the complete code:
Get rid of this code:
and instead, add a global variable p:
and increment it in your drawBar() function: